0

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

Mayukh Bhattacharya
  • 12,541
  • 5
  • 21
  • 32
Bikat Uprety
  • 139
  • 8

1 Answers1

0

You could do it like this:

With ActiveSheet
    .Range("C3", .Cells(3, Columns.Count).End(xlToLeft)).Offset(-1).Value = .Range("A2").Value
End With
Tim Williams
  • 154,628
  • 8
  • 97
  • 125