'Autofill across and above a dynamic range

I'd like to autofill cells across and above a dynamic range.

I have a line of numbers in row 3 and would like to put the word "Customer No." in the cell above each one.

enter image description here

I do this by copying A2 and pasting into C2 then dragging across

enter image description here

Via VBA macro recorder the code I get looks like this

Selection.Copy
Range("C2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.AutoFill Destination:=Range("C2:E2"), Type:=xlFillDefault
Range("C2:E2").Select

I was wondering if there's a way to create an autofill across a dynamic range as the number of cells in row 3 will change from time to time?

Thanks



Solution 1:[1]

You could do it like this:

With ActiveSheet
    .Range("C3", .Cells(3, Columns.Count).End(xlToLeft)).Offset(-1).Value = .Range("A2").Value
End With

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1