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

Occupied cell count

Status
Not open for further replies.

phudgens

Technical User
Jul 8, 2004
117
US
I'm thinking there's got to be an easy way to get Excel VBA to return the count of occupied cells in a specified column. I tried HdrCnt = Columns("A:A").Count but that just returns 1 regardless of what is in the column. Thanks.
 


Hi,

Why do you need VBA to do that?
[tt
=COUNTA(A:A)
[/tt]


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
or Hi-light the column e.g.click on the column header A

then on the bottom line of your spreadsheet (where it says Ready in the lower left) Right click and choose any of the following: none, avg, count, count numbers, max, min or sum and your results appear on that bottom line.

sam




 
I'm doing this in VBA because I want to know if the user has loaded data on which to run the program. If data has not been loaded, I give the user a message to load data. I've figured it out though:

With Workbooks(ThisWkBk).Worksheets(HdrWks)
RowCount = Columns("A:A").Rows.Count
End With
LastRow = "A" & RowCount
HeaderCnt = .Range("A1", .Range(LastRow).End(xlUp)).Rows.Count

 



Hardly!
Code:
msgbox application.Workbooks(ThisWkBk).Worksheets(HdrWks).counta("A:A")


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top