SQLUser
SQLUser

Reputation: 123

VBA: How to find the first unhidden row

I have been using the following to find the last unhidden row:

Dim lrow As Long
lrow = Cells(Rows.Count, "A").End(xlUp).Row

How would I do the same for the first unhidden row?

EDIT: I'd like to find the first unhidden row excluding A1.

Upvotes: 0

Views: 513

Answers (1)

Chronocidal
Chronocidal

Reputation: 7951

Dim lRow As Long
lRow = ActiveSheet.Columns(1).SpecialCells(xlCellTypeVisible).Row

Get the Row of the first visible cell in Column A (a.k.a. Column 1), regardless of whether or not it contains any data


Since the question has been modified to request that Row 1 be excluded from the test, here's a version for that:

Dim rTestRange AS Range, lRow AS Long
Set rTestRange = ActiveSheet.Range(ActiveSheet.Cells(2,1), _ 'Start from Row 2
    ActiveSheet.Cells(ActiveSheet.Rows.Count,1)) 'Until the bottom row of the sheet
lRow = rTestRange.SpecialCells(xlCellTypeVisible).Row 'First visible row

Upvotes: 3

Related Questions