SOLVED

Count rows, end up will not work with only one row

Copper Contributor

I'm using the below code to find the last row, then autofill column A. 


LR = Cells(Rows.Count, 4).End(xlUp).Row
Range("A2").AutoFill Destination:=Range("A2:A" & LR)

 

It works unless there is only one value in column 4 (D2). If there are no values in D2 or if there is more than one value in column D (D2:D3... D2:D2000) the formula works. 

 

What do I need to do if there is only one value in column D (D2)?

Row A1:E1 are column heads.

 

Tank you for your help!

2 Replies
best response confirmed by starr0650 (Copper Contributor)
Solution

@starr0650 

For example:

    LR = Cells(Rows.Count, 4).End(xlUp).Row
    If LR <> 2 Then
        Range("A2").AutoFill Destination:=Range("A2:A" & LR)
    End If
Thanks Hand! This worked perfectly.
1 best response

Accepted Solutions
best response confirmed by starr0650 (Copper Contributor)
Solution

@starr0650 

For example:

    LR = Cells(Rows.Count, 4).End(xlUp).Row
    If LR <> 2 Then
        Range("A2").AutoFill Destination:=Range("A2:A" & LR)
    End If

View solution in original post