user6533517
user6533517

Reputation: 25

Clear contents and fill with new value up to last row, but how to keep LastRow?

I have a question about saving the rownumber and then filling data with it in the next for loop like below. However, when I run this, it runs the code to find the LastRow again which then does not exist anymore as it's empty.

Sub kolomE()

Dim i, j As Integer
Dim LastRow As Long
With ActiveSheet
     LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row    
End With

Range("E3:E3" & LastRow).ClearContents
Range("E3:E3" & LastRow) = "&omegaOne="

End Sub

So I want it to fill the cells it cleared with .ClearContents to fill it with "&omegaOne="

Upvotes: 0

Views: 3047

Answers (1)

Limak
Limak

Reputation: 1521

You forgot to erase row number from your ranges. It should be:

Range("E3:E" & LastRow).ClearContents
Range("E3:E" & LastRow).Value = "&omegaOne="

Upvotes: 1

Related Questions