Ravi Gowda
Ravi Gowda

Reputation: 31

How to get the count of rows in a sheet?

I am trying this code

row = 2
With Summary
    .Range("$A$1:$A$100").RemoveDuplicates Columns:=1, Header:=xlYes
    For row To .Rows.Count
        .Cells(row, 2) = 1
        row = row + 1
    Next row
End With

but I get a syntax error in the for loop statement

How should this look like?

Upvotes: 0

Views: 45

Answers (1)

Gary's Student
Gary's Student

Reputation: 96753

You do not need a Loop:

Sub dural()
    Dim N As Long, summary As Worksheet
    Set summary = ActiveSheet

    With summary
        .Range("$A$1:$A$100").RemoveDuplicates Columns:=1, Header:=xlYes
        N = .Cells(Rows.Count, 1).End(xlUp).Row
        .Range("B2:B" & N).Value = 1
    End With
End Sub

Note: The code assumes there is nothing else in column A.

Upvotes: 1

Related Questions