autofill multiple formula in specific columns

MKLAQ

Active Member
Joined
Jan 30, 2021
Messages
415
Office Version
  1. 2016
Platform
  1. Windows
hi
I try autofilling the formulas in specific ranges but it shows application defined or object defined error in this line
VBA Code:
 .Range("C2:E2").Formula = strFormulas
Code:
Sub FillDown()

    Dim strFormulas(1 To 3) As Variant

    With ThisWorkbook.Sheets("Sheet1")
        strFormulas(1) = "=IFERROR(HOUR(B9-$B$3)*30+MINUTE(B9-$B$3);"")"
        strFormulas(2) = "=PRODUCT(A2:B2)"
        strFormulas(3) = "=A2/B2"

        .Range("C2:E2").Formula = strFormulas
        .Range("C2:E11").FillDown
    End With
    End Sub
any help to fix it ,please ?
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
The first formula should be
VBA Code:
        strFormulas(1) = "=IFERROR(HOUR(B9-$B$3)*30+MINUTE(B9-$B$3),"""")"
 
Upvote 0
OK, we got a bunch of things going on here.

1. I don't think you can populate a range of different formulas like that at once like that. If "strFormulas" is an array, you need to use an index with it to designate which one.
2. Your last formula should have """" instead of "" at the end, since you want literal quotes.
3. Do NOT use reserved words like "FillDown" as the name of your procedures, functions, and variables! This ambiguity can cause erorrs and unexpected results. When you reference "FillDown", Excel cannot be sure if you are referring to the FillDown method (which you are actually using right in your code!) or your FillDown procedure.

Here is fixed up code (no need for the array variable at all, it isn't saving you anything):
VBA Code:
Sub MyFillDown()

    With ThisWorkbook.Sheets("Sheet1")
        .Range("C2").Formula = "=IFERROR(HOUR(B9-$B$3)*30+MINUTE(B9-$B$3);"""")"
        .Range("D2").Formula = "=PRODUCT(A2:B2)"
        .Range("C2").Formula = "=A2/B2"
        .Range("C2:E11").FillDown
    End With
   
End Sub
 
Upvote 0
Solution
You are welcome.
Glad we were able to help.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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