syntax in exporting data to excel

G

Guest

With objActiveWkb
.Worksheets(1).Cells(1, 1).Value = DLookup("F2", "Election Table - Actual File Query", "RowNum = 5")
.Worksheets(1).Cells(1, 2).Value = DLookup("F3", "Election Table - Actual File Query", "RowNum = 5")
.Worksheets(1).Cells(1, 3).Value = DLookup("F4", "Election Table - Actual File Query", "RowNum = 5")
.Worksheets(1).Cells(1, 4).Value = DLookup("F5", "Election Table - Actual File Query", "RowNum = 5")
End With

The above code pulls information from a query and exports it to an excel worksheet one item at a time. After these four fields are filled, i want it to step down to the next row and fill in cells (2,1) (2,2) (2,3) and (2,4) and then onto row 3, 4, 5, etc..

Rather than copy/pasting the above code over and over and changing the row number, I want to use a loop that steps the variable NumCount by 1 each time through the loop. This will increase the row number each time it loops around. The problem is i can't use a variable in the syntax ".Worksheets(1).Cells(NumCount, 4)" Is there a way to use a variable as shown here as opposed to explicitly giving a row number?

I have the same trouble in using the variable NumCount in the syntax at the end "RowNum = NumCount"... again it doesnt work unless i explicity use a number rather than a variable.

Any help?
 
G

Guest

Oops, i apologize... it was only a silly error preventing me from doing exactly as i intended. All fixed now.
 

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

Top