Few days Back I got a requirement of posting few excell related code…..
Hi Animesh,Can you please tell me the exact code for Get Column Count in ExcelI need to code very urgentRegardsRobin
Set ExcelFile = CreateObject(“Excel.Application”)
‘You can set it to false as well
ExcelFile.Visible = true
‘Open the Excel file
‘Get the 1st sheet (can be change to some other index number)
Set ExcelSheet = ExcelFile.Sheets.Item(1)
‘Get the number of columns
Cols = ExcelSheet.UsedRange.Columns.Count
msgbox “No of Columns: ” & Cols
Set ExcelSheet = nothing
Set ExcelFile = nothing
one more good piece of code is ..
Here is a simple piece of code that will give you the column count.even you can get the column name as well..here we go…
On Error Resume Next
i = i + 1
sColName = DataTable.GetSheet(sSheetName).GetParameter(i).Name
Loop While 0 = Err.Number
‘GetParameter throws an error when using an index that is out of bounds …
‘We can use this functionality to ASSUME that it’s an unused column.
‘We’ve come to the end of our USED columns
GetColCount = i – 1
On Error GoTo 0
Just let me know what more you want.