Selected Answer
Mussa
You code will work if there's a value in B2 only since otherwise your test If LR <> "" Then tries to test the value of a range of cells (which VBA won't do but you can set the value of a range to a single value)
This code loops through each cell (which I've called Cl) in the used range of column B and, if there's a value, puts a row number (less 1) in column A using the Offset function:
Sub autnn()
Dim Cl As Range
For Each Cl In Range("B2:B" & Range("B" & Rows.Count).End(xlUp).Row)
If Cl.Value <> "" Then
With Cl.Offset(0, -1)
.Formula = "=ROW()-1"
.Value = .Value
End With
End If
Next Cl
End Sub
In fact you don't need the block If and With statement; you can use the single line:
If Cl.Value <> "" Then Cl.Offset(0, -1).Value =ROW()-1
If you don't need to test first if column B is filled then you could add numbers to the entire offset range using:
<<your defined range>>.Offset(0, -1).Value =ROW()-1
Hope this helps.