Need a VB Autofill solution

MtyAVATAR

New Member
Joined
Jul 16, 2015
Messages
7
I pull reports that has data in columns A thru AD but the rows of data can vary.

I am trying to write a simple VB code to paste 8 formulas in rows AE thru AL and paste them down to the end of the data set but I keep getting an error on the 4th line where I try to define "LRow". If I remove this line, the VB works but only copys the formula down 19 rows instead of to the end of the data set.

I am sure it is something simple but this is my first year working with VB and self teaching myself as I go. I have spent almost 2 hours trying to resolve this error to no avail.

Code:
Sub FillDown()

    Dim strFormulas(1 To 8) As Variant
    Dim LRow As Long    
         LRow = Range("A:A" & Rows.Count).End(x1Up).Row
    
    With ThisWorkbook.Sheets("Sheet1")

        'ZGLR
        strFormulas(1) = "=IFERROR(N2/L2,0)"
        
        'DIS
        strFormulas(2) = "=IFERROR(AB2/L2,0)"
        
        'ZIBE
        strFormulas(3) = "=IFERROR(T2/SUM(N2+AB2),0)"
        
        'ZICM
        strFormulas(4) = "=IFERROR(U2/L2,0)"
        
        'ZIGN
        strFormulas(5) = "=IFERROR(V2/SUM(N2+AB2+T2+U2),0)"
        
        'ZOBE
        strFormulas(6) = "=IFERROR(W2/SUM(N2+AB2+T2+U2+V2),0)"
        
        'ZOCM
        strFormulas(7) = "=IFERROR(X2/L2,0)"
        
        'ZOGM
        strFormulas(8) = "=IFERROR(Y2/SUM(N2+v),0)"

     .Range("AE2:AL2").Formula = strFormulas
     .Range("AE2:AL2" & LRow).FillDown
        
    End With

End Sub
 
Last edited:

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Place your LR after:

Code:
With ThisWorkbook.Sheets("Sheet1")

then use a dot

Code:
LRow = .Range("A" & Rows.Count).End(xlUp).Row

also this line is incorrect:

Code:
.Range("AE2:AL2" & LRow).FillDown

Change it to:

Code:
.Range("AE2:AL" & LRow).FillDown
 
Upvote 0
Looks like this:

Code:
strFormulas(8) = "=IFERROR(Y2/SUM(N2+v),0)"

should be:

Code:
strFormulas(8) = "=IFERROR(Y2/SUM(N2+V2),0)"
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top