mustish1
asked on
Skip First Row
Hi: Can any one please tell me how to i skip first record in the do while loop as the first row in the excel sheet is the headings
Thanks.
Private Sub readExcelFile()
Dim objConn As ADODB.Connection
Dim objRec As ADODB.Recordset
Dim strFileName As String
Dim strSheet As String
Dim arrData As Variant
strFileName = "C:\REMITandNSF\remit.xls" 'name of the Excel file
strSheet = "Sheet1" 'name of worksheet within the Excel file
Set objConn = New ADODB.Connection
objConn.Open "Provider=Microsoft.Jet.OL EDB.4.0; Data Source=" & strFileName & ";Extended Properties=""Excel 8.0;"""
Set objRec = New ADODB.Recordset
strtest = "SELECT * FROM [" & strSheet & "$]"
Debug.Print strtest
objRec.Open "SELECT * FROM [" & strSheet & "$]", objConn, adOpenKeyset, adLockReadOnly
Do While Not objRec.EOF
MsgBox objRec.Fields(0).Value
MsgBox objRec.Fields(1).Value
objRec.MoveNext
Loop
objConn.Close
Set objRec = Nothing
Set objConn = Nothing
End Sub
Thanks.
Private Sub readExcelFile()
Dim objConn As ADODB.Connection
Dim objRec As ADODB.Recordset
Dim strFileName As String
Dim strSheet As String
Dim arrData As Variant
strFileName = "C:\REMITandNSF\remit.xls"
strSheet = "Sheet1" 'name of worksheet within the Excel file
Set objConn = New ADODB.Connection
objConn.Open "Provider=Microsoft.Jet.OL
Set objRec = New ADODB.Recordset
strtest = "SELECT * FROM [" & strSheet & "$]"
Debug.Print strtest
objRec.Open "SELECT * FROM [" & strSheet & "$]", objConn, adOpenKeyset, adLockReadOnly
Do While Not objRec.EOF
MsgBox objRec.Fields(0).Value
MsgBox objRec.Fields(1).Value
objRec.MoveNext
Loop
objConn.Close
Set objRec = Nothing
Set objConn = Nothing
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Happy to help again! :^)