Excel in VB6

  • Thread starter Thread starter Nats Buls
  • Start date Start date
N

Nats Buls

How can i write the code such that when it reach filling the end of the
row of an excel worksheet, it will continue filling the other sheet let
say sheet2.
 
It really depends on what you are doing and how you are doing it, but

if rw >= 65536 then
set sh = sh.Next
rw = 1
End
sh.Cells(rw,1) = "some value"

However, there is no built in method to fill multiple worksheets with a
single command such as writing an ADO recordset or reading a text file
(unless one was added in xl2002/2003 and I don't recall that they have).
 
Nats said:
How can i write the code such that when it reach filling the end of the
row of an excel worksheet, it will continue filling the other sheet let
say sheet2.

Here's a suggestion (thanks TK). Using Excel's CopyFromRecordset on a
recordset with more records than the 65536 maximum worksheet rows does
not cause the method to fail. Rather, the cursor is merely moved e.g.
to record 65537. Therefore, you could do something like this:

Sub test()
Dim rs As Object
Set rs = CreateObject("ADOR.Recordset")
rs.Open _
"SELECT * FROM 100K_row_table;", _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Tempo\New_Jet_DB.mdb"

Dim Counter As Long
With Workbooks("MyWorkbook.xls")
Do While Not rs.EOF
Counter = Counter + 1
.Worksheets(Counter).Range("A1") _
.CopyFromRecordset rs
Loop
End With
End Sub

Jamie.

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top