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.
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.