Wednesday, November 25, 2009

Displaying Data From Data into Excel Worksheet

Displaying the data from the database into Excel.

When you have accomplished this, you need to display the data within your worksheet.

Add the following to your function to display the data within your Worksheet.

Dim ws As Worksheet
Dim count As Long

Set ws = ThisWorkbook.Worksheets(1) 'The number is the number of the worksheet in Excel. If you have multiple worksheets, then you will adjust the number accordingly.

You can input data into your Excel worksheet like this:

ws.Cells(1, 1) = "Name"
ws.Cells(1, 2) = "Area"

To add data from your record set you can change your loop like this:

While Not rec.EOF
ws.Cells(count, 1) = rec("title") 'title and area is the column name from your database
ws.Cells(count, 2) = rec("area")
count = count + 1
rec.MoveNext
Wend

0 comments: