Use VBA to Autofill a Row until the end of the number of data in another row

New Contributor

I need some help with the following problem:


I need to built a Macro that could make the following thing:


The Macro should select the first cell with a value and autofill with the same value until the last row that contain the next value that its different.


The thing looks like this:



 And i want to make this in Macro




Thank you very much in advance,


3 Replies
best response confirmed by jorgeliber (New Contributor)



Please try this...


Sub Autofil()
Dim Rng     As Range
Dim lr      As Long

Application.ScreenUpdating = False

lr = Range("A" & Rows.Count).End(xlUp).Row

On Error Resume Next
Set Rng = Range("X2:X" & lr).SpecialCells(xlCellTypeBlanks)
On Error GoTo 0

If Not Rng Is Nothing Then
    Rng.Formula2R1C1 = "=R[-1]C"
    Range("X2:X" & lr).Value = Range("X2:X" & lr).Value
End If

Application.ScreenUpdating = True
End Sub
Thanks for your response. You earn my respect and save my **bleep**.