Home » excel » excel vba – VBA Range.Rows.Count giving unexpected results

excel vba – VBA Range.Rows.Count giving unexpected results

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have a Range variable that contains an address – $2:$2,$4:$205,$214:$214 – (3 groups of rows).

I would like to get the count of all the rows in that range.

However, range.Count gives me the count of all the cells (50,000~) and range.Rows.Count only return 1 – the count of all the rows in the first group. How do I get the count of all the rows

Thanks

How to&Answers:
Dim rowCount As Long
Dim ctr As Long

'You could use your range variable in place of Selection below
For ctr = 1 To Selection.Areas.Count
    rowCount = rowCount + Selection.Areas(ctr).Rows.Count
Next
Debug.Print rowCount