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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counting the total number of columns on a single sheet

Status
Not open for further replies.

BlueScr33n

Instructor
Feb 10, 2003
78
US
Was wondering how to get the total number of columns containing data in an excel sheet. Any links, help (even code) would be appreciated!
 
Sorry, I should clarify - Would need to do this as a VBA based macro.
 
The simplistic approach is to use
[blue]
Code:
   ActiveSheet.UsedRange.Columns.Count
[/color]

But there are several caveats regarding cells with formatting but no data and handling of the situation where column A is not the first column with data. If your situation is not simple, try a search in this forum for "UsedRange" to see the variations. There are also a couple of FAQ's on the subject.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top