Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking No of Fields in an Excel file - help required

Status
Not open for further replies.

Sech

Programmer
Jul 5, 2002
137
GB
I am using a File Selection window with an import process in my database. After the user selects the excel file to import, I would like to use some code to check the first record of the file and count the number of valid fields. Also any other checks that could identify whether or not the file was valid would be useful. Does anyone know how to do this?
 
You could obviously also use the ActiveSheet object rather than pass a worksheet.

Public Function GetLastRow(oWs As Worksheet) As Long

On Error Resume Next

With oWs.Range("a1").CurrentRegion
mlngLastRow = oWs.Cells(.Rows.Count, 1).Row
End With
GetLastRow = mlngLastRow

End Function

Public Function GetLastCol(oWs As Worksheet) As Long

With oWs.Range("a1").CurrentRegion
mlngLastCol = oWs.Cells(1, oWs.Columns.Count).Column
End With
GetLastCol = mlngLastCol

End Function
----------------------
scking@arinc.com
Life is filled with lessons.
We are responsible for the
results of the quizzes.
-----------------------
 
This almost works except that it brings back ALL the valid columns in the spreadsheet i.e. 256 instead of just the columns which have data in...any ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top