COUNT within a range

Carl Clements

Board Regular
Joined
Jun 13, 2008
Messages
95
Hi,

Is there some code that counts the number of columns and rows in a range of cells? I want the macro to count until it finds an empty cell. I assume the COUNTA function will be involved.

The worksheet contains data from A26 to J34 and I want the formula to ignore rows above A26.

Thanks,
Carl
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hope you find it useful, this works fine with me..

Code:
Sub count()
cnt = 0
col = 1
    While Cells(26, col) <> Empty and col <= 10
        'lRow = Cells(Rows.count, col).End(xlUp).Row --> to find for last non-empty row
        'lCol = Cells(26, Columns.count).End(xlToLeft).Column  --> to find for the last non-empty column
        For j = 26 To 34 ' as per your requirement of A26 to J34
            If Cells(j, col) <> Empty Then
                cnt = cnt + 1
            Else
                GoTo Result
            End If
        Next j
        col = col + 1
    Wend
    col = col - 1
Result:
MsgBox "There are [" & cnt & " Rows] and " & "[" & col & " Columns] within the range" & vbCrLf & _
            "before reaching the empty cell.", , "Counting Columns and Rows"
End Sub

Open for comments.
Thanks God bless
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

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