Counting the number of Occupied Rows in workbook.

Status
Not open for further replies.

Pankaj Sharma

New Member
Joined
Oct 13, 2014
Messages
5
I was trying to count he number of occupied rows in the workbook.
Below is the code I am using. But I am getting the wrong results.

Private Sub CommandButton1_Click()

Dim count
Dim WkSht As Worksheet
Application.DisplayAlerts = False
For Each WkSht In ActiveWorkbook.Worksheets
count = ActiveSheet.UsedRange.Rows.count
MsgBox (count)
Next WkSht


Message box is showing the same value for count even if all the sheets have different number of rows occupied. Looks like control is not navigating to next sheet in loop.

Any help is welcomed.
;)

 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
You already have this question asked here.

Please do not post the same question multiple times. Questions of a duplicate nature will be locked or deleted, per #9 of the Forum Rules.

Any bumps, clarifications, or follow-ups should be posted to the linked thread.


In any case you question is in English so should not be posted in this forum which is for "Questions in Other Languages".
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,215,066
Messages
6,122,947
Members
449,095
Latest member
nmaske

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top