No Heading Row

G

Greg Maxey

For some practice with Word, I created a very simple spreadsheet that
contained a 3 x 3 cell range that I named "mySSrange"

In the cells I entered:

Cat Dog Hampster
Cow Pig Sheep
Wolf Badger Bear

When I run this code the first message displayed is "Cow." It seems
that Excel is making my first row a heading or something. How do I
modify this code or my spreadsheet so that the default A B C is
the heading and all rows of data I enter are treated as data and not a
heading. Thank you.

Sub ScratchMacro()
'Set Reference to "Microsoft DAO 3.51 (or 3.6) Object Library".
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim i As Long
Set db = OpenDatabase("C:\Book1", False, False, "Excel 8.0")
Set rs = db.OpenRecordset("SELECT * FROM `mySSRange`")
'Loop through each recordset.
While Not rs.EOF
For i = 0 To rs.Fields.Count - 1
MsgBox rs.Fields(i).Value
Next i
rs.MoveNext
Wend
'Clean up.
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
End Sub
 

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