Home > Net >  Autofill doesn't stop at the range specified
Autofill doesn't stop at the range specified

Time:12-17

I have a question. When

I ran the code below to autofill to a range (sheets will have different lengths of rows). In my example, the length I am filling down to is only 6 and only the first column (Column U) fills correctly. The rest go to the bottom of the sheet at 10000.

Sub MacroFill () 
Dim LastRow As Long LastRow = Range("T4").CurrentRegion.Rows.Count   1 
Range("U4:U" & LastRow).FillDown 
Range("V4:U" & LastRow).FillDown 
...
Range("AZ4:AZ" & LastRow).FillDown
End Sub()

The columns I am trying to autofill down are from U:AZ. Is there a more efficient way to get them autuofill based on how many number of rows have data in a specified column( in my case column T4:T)?

Thank you

I tried to create multiple LastRow variables and label them for each row but its not efficient. I tried to combine in the Range of the length of my rows.

CodePudding user response:

I think it's because you referenced Col U twice.
Either that or your lastrow reference.
Try this:

Sub MacroFill()
    Dim LastRow As Long
    LastRow = Range("T" & Rows.Count).End(xlUp).Row
    Range("U4:V" & LastRow).FillDown
    '...
    Range("AZ4:AZ" & LastRow).FillDown
End Sub
  • Related