Forum Discussion
SAckerman
Jan 12, 2021Copper Contributor
Excel - Enter Numbers in a column
Excel VBA macro-Need help to correct macro-number rows in a column I am a novice on this site and Excel VBA within macros. Trying to finish the macro without errors. Using pick button to ru...
Boriana Petrova
Jan 27, 2021Copper Contributor
you can check this:
Sub Button1_Click()
Dim LastRow As Long, Firstrow As Long
Dim r As Long
Dim c As Integer
With ActiveSheet
Firstrow = 10
'counter - how many rows you have
LastRow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
For r = LastRow To Firstrow Step -1
If .Range("B" & r).Value = "" Then
.Range("B" & r).EntireRow.Delete
'counter - how many rows were deleted
c = c + 1
End If
Next r
End With
Range("A10").Select
ActiveCell.Value = "1"
'use both variable to calculate new last row 🙂
Selection.AutoFill Destination:=Range(("A10:A" & LastRow - c)), Type:=xlFillSeries
End Sub