Few days (Excel) 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

Get Column Count in Excel
Function getColoumnNumber()
Set ExcelFile = CreateObject(“Excel.Application”)
‘You can set it to false as well
ExcelFile.Visible = true
‘Open the Excel file
ExcelFile.Workbooks.Open “C:Demo.xls”
‘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
End Function

Get Column Count in Excel
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…
Public Function GetColCount (sSheetName)
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
End Function

Just let me know what more you want.

Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

I am the founder and owner of the blog - TechTravelHub.com, always love to share knowledge on test automation,tools,techniques and tips.I am a passionate coder of Java and VBScript.I also publish articles on Travel ideas and great honeymoon destinations.Apart from these, I am a gear-head,love to drive across India. I have shared lots of articles here on How to travel several parts of India.Customization of cars aka car modification is my another hobby.Get in touch with me on [email protected]

1 Comment

  1. very helpful for me.I’d have to examine with you here. Which is not one thing I usually do! I take pleasure in reading a post that may make folks think. Additionally, thanks for permitting me to comment!

Write A Comment