anusdesai
asked on
How can I count the number of rows in an excel sheet column...
Hi,
How can I count the number of rows in an excel sheet column...
Function (byval col as integer)
will return number of rows
How can I count the number of rows in an excel sheet column...
Function (byval col as integer)
will return number of rows
ASKER
Hi,
Public Function unusedexcel(ByVal workbook As String, ByVal ExcelSheetName As String, ByVal row As Integer, ByVal col As Integer)
'Dim SpreadSheetProfund As String
'SpreadSheetProfund = "J:\Implementation\PHT_vss \RegularIn terface\Fi les\Person al_Details .xls"
Try
Dim xlApp As Object = CreateObject("Excel.Applic ation")
Dim xlWB As Object = xlApp.Workbooks.Open(workb ook)
Dim xlWS As Object = xlWB.Worksheets(ExcelSheet Name) ' change the name of the sheet you require
GetColumnRowCount(1, xlWS)-------your function
xlWB.Close()
xlApp.Quit()
xlWS = Nothing
xlWB = Nothing
xlApp = Nothing
i get get erro type mismatch
Catch ex As Exception
MsgBox(ex.ToString)
AddMessage("Spread sheet record count - " & FormatMessage(12, Err.Number, Err.Description))
AddMessage("Error processing 'Count Rows', please contact your consultant")
End Try
End Function
Public Function unusedexcel(ByVal workbook As String, ByVal ExcelSheetName As String, ByVal row As Integer, ByVal col As Integer)
'Dim SpreadSheetProfund As String
'SpreadSheetProfund = "J:\Implementation\PHT_vss
Try
Dim xlApp As Object = CreateObject("Excel.Applic
Dim xlWB As Object = xlApp.Workbooks.Open(workb
Dim xlWS As Object = xlWB.Worksheets(ExcelSheet
GetColumnRowCount(1, xlWS)-------your function
xlWB.Close()
xlApp.Quit()
xlWS = Nothing
xlWB = Nothing
xlApp = Nothing
i get get erro type mismatch
Catch ex As Exception
MsgBox(ex.ToString)
AddMessage("Spread sheet record count - " & FormatMessage(12, Err.Number, Err.Description))
AddMessage("Error processing 'Count Rows', please contact your consultant")
End Try
End Function
where abouts does the error occur?
Also, you're not using the value returned by the function. It meant to be used like this....
Dim RowCount As Integer = GetColumnRowCount(8, xlWS)
Wayne
Also, you're not using the value returned by the function. It meant to be used like this....
Dim RowCount As Integer = GetColumnRowCount(8, xlWS)
Wayne
also, which function are you using?
ASKER
oki will try and be back
ASKER
your function:
Public Function GetColumnRowCount(ByVal col As Integer, ByVal xlWorksheet As Object)
Try
Return xlWorksheet.Application.In tersect(xl Worksheet. UsedRange, xlWorksheet.Columns(col)). Rows.Count
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Function
Same error type mismatch...com exception...
Public Function GetColumnRowCount(ByVal col As Integer, ByVal xlWorksheet As Object)
Try
Return xlWorksheet.Application.In
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Function
Same error type mismatch...com exception...
are you sure the exception is originating from the function?
ASKER
Yup!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Again Amazing!!
Cheers mate
Cheers mate
ASKER
Hi Wayne,
I need one more help in excel...see my next question ..
I will be great if you help me in that....
I need one more help in excel...see my next question ..
I will be great if you help me in that....
ASKER
It will be great..sorry for the spelling mistake
Try this function....
Public Function GetColumnRowCount(ByVal col As Integer, ByVal xlWorksheet As Object)
Return xlWorksheet.Application.In
End Function
So you need to pass 2 arguments. The column "col", and the Excel Worksheet object, which is the worksheet containing the column you need to retrieve the row count from. An example, using the declarations from your previous question....
Dim RowCount As Integer = GetColumnRowCount(8, xlWS)
NOTE: The above function also counts blank cells. It returns the number of rows from the first to the last value in that column. To count only those cells with values, use this function....
Public Function GetColumnRowCount(ByVal col As Integer, ByVal xlWorksheet As Object)
Return xlWorksheet.Application.Wo
End Function
Regards,
Wayne