473,396 Members | 1,970 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to select rows randomly in MSFLexGrid and export them to excel?

143 100+
Hello All,

I want to select few rows randomly in the MSFlexGrid and export them to excel using a button which i had made..
already i can send all the record in the grid using my export button bt wht if i want to select few rows randomly and not all and send them to excel sheet?
i knw selectionmode is thr in MSFlexGrid and i can set tht to flexselectionbyrow bt tht doesnt happen for random record...
does anyone can help me in that?
thank u
Jul 11 '12 #1
5 4223
Guido Geurs
767 Expert 512MB
Is this a MSflexgrid in Excel?
Is it possible to attach your program in Bytes so we can work on the same structure and data?
If the data is confidential, please replace it with fictive but representative data.(not to much! ,+- 20 records just to see the structure)
Jul 12 '12 #2
squrel
143 100+
Thank u very much for the reply and helping me here... this is my Grid and the next is my excel button..
once i press on the excel button i can export the whole grid to the excel sheet bt what if i dont want to export the whole data to excel and i want few rows in tht.. for eg. row1,row3 and row7..
how to do tht?
thank u very much in advance



Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Function LoadAddressGridData(FinYrCode As Integer)
  3.  
  4. Dim sqlQuery As String
  5. sqlQuery = "select PoNo,AmendNo,Yy,Vendornm,convert(VarChar(20), PoDate, 6) As PoDate,UnitNm, adr1 as Address,adrcity as City,statenm as State,"
  6. sqlQuery = sqlQuery & "adrpin as Pin,adrcontact as Contact,adrphone as Phone from msaddress adr,"
  7. sqlQuery = sqlQuery & "txpohdr hdr, msunits unit,msstates state,"
  8. sqlQuery = sqlQuery & "msvendors ven where adrof='U'and adrforid=hdr.unitid"
  9. sqlQuery = sqlQuery & " and adrid = hdr.shiptoadrid And hdr.vendorid = Ven.vendorid"
  10. sqlQuery = sqlQuery & " And hdr.unitId = unit.unitId And State.stateid = adrstate"
  11. sqlQuery = sqlQuery & " And hdr.yy = '" & cmbYear.Text & "' And hdr.Ind = 1"
  12. sqlQuery = sqlQuery & " and vendornm='" & cmbVendorNm.Text & "'"
  13.  
  14.  
  15. On Error GoTo ChkErr
  16.     Adodc1.ConnectionString = pStrConnectionString
  17.     Adodc1.RecordSource = sqlQuery
  18.     Adodc1.Refresh
  19.     MSHFlexGrid1.ColWidth(1) = 600
  20.     MSHFlexGrid1.ColWidth(2) = 800
  21.     MSHFlexGrid1.ColWidth(3) = 600
  22.     MSHFlexGrid1.ColWidth(4) = 2000
  23.     MSHFlexGrid1.ColWidth(5) = 1000
  24.     MSHFlexGrid1.ColWidth(6) = 2000
  25.     MSHFlexGrid1.ColWidth(7) = 2500
  26.     MSHFlexGrid1.ColWidth(8) = 1000
  27.     MSHFlexGrid1.ColWidth(9) = 1500
  28.     MSHFlexGrid1.ColWidth(10) = 1500
  29.     MSHFlexGrid1.ColWidth(11) = 1500
  30.     MSHFlexGrid1.ColWidth(11) = 1500
  31.     MSHFlexGrid1.Refresh
  32.     sortedBy = 1
  33.  
  34. Exit Function
  35. ChkErr:
  36. If Err.Number > 0 Then
  37. MsgBox Err.Number & vbNewLine & Err.Description
  38.            Call ErrHand("frmVendorWiseOrders", "LoadAddressGridData")
  39.     'Resume Next
  40. End If
  41. End Function
  42.  
  43.  

My excel code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cmdExport_Click()
  3. Dim q As Long
  4. Dim p As Long
  5. Dim newCell As String
  6. Dim xl As Excel.Application
  7. If MSHFlexGrid1.Text <> "" Then
  8. Set xl = CreateObject("excel.application")
  9.     xl.Workbooks.Open (App.Path & "\Book1")
  10.     DoEvents
  11.     xl.Visible = True
  12.  
  13. For p = 0 To MSHFlexGrid1.Rows - 1
  14.     For q = 0 To MSHFlexGrid1.Cols - 1
  15.         MSHFlexGrid1.Col = q
  16.         MSHFlexGrid1.Row = p
  17.         newCell = Chr(q + 65) & p + 1
  18.         xl.Worksheets("Sheet1").Range(newCell).Value = MSHFlexGrid1.Text
  19.     Next
  20. Next
  21. End If
  22. End Sub
  23.  
  24.  
Jul 13 '12 #3
Guido Geurs
767 Expert 512MB
Attached is an example how to randomize some rows in an MSflexgrid in VB6.
I'm working on an example in VBA for Excel 2003.
Jul 16 '12 #4
Guido Geurs
767 Expert 512MB
Attached is an example in Excel.
Jul 16 '12 #5
squrel
143 100+
Thank u very much for ur help.. i got it..
Jul 18 '12 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: ABC | last post by:
What methods can export excel file from stored procedure with parameters which input from web form?
1
by: khairulfnd | last post by:
i wanna know the function when u select rows in the datagrid, it will be postback to a gridview where should i put it
1
by: panku007 | last post by:
hi All, I wanted to export excel data into ms word document through java coding.So please send me reply,according to my question. thanks
2
by: sladjana21 | last post by:
Hello, is it possible to select rows form a table, where column with datetime is null, something like: SELECT * FROM MYTABLE WHERE DATE_COLUMN = NULL there is no error, but doesn't return any...
2
by: tbenchakroune | last post by:
How can I export Excel spreadsheets to Access db? Thanks, T.
1
by: san1014 | last post by:
Hi How to import and export excel data into oracle database using java. Thank you
1
by: CF FAN | last post by:
Can Report Builder Export Excel Files with multiple Sheets How can I create a report that it can export in excel by multiple
3
by: minhtran | last post by:
Hi all Anyone has any idea how to get a Excel header column in VB.NET. Please, help me. Thank you so much in advance
0
by: Dubois | last post by:
Bonjour Lorsque je lance un export excel au travert d'une page en ASP.NET C#, cela fonctionne sur la machine de développement, par contre, sur le serveur de production j'ai l'erreur suivante : ...
3
by: prashantdixit | last post by:
Hi, I am trying to export excel data to text file in a particular format. The Format for each ROW of Excel is like IMAN_ROOT/bin/import_file -f=<Column A> -type=<Column B> -d=<Column C>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.