VA help to enter array formula

asad

Well-known Member
Joined
Sep 9, 2008
Messages
1,434
Hello All,

I am trying to enter following array formula using VBA. But it does not change the lookup cell. Can someone please help me out?

Code:
Range("C6:C29").Formula = "=ROUND($J$1*SUM(IF($P$6:$P$293=[B]A6[/B],[COLOR=#FF0000][/COLOR]IF(MONTH($Q$6:$Q$293)=MONTH($E$1),$R$6:$R$293))),0)"

"A6" in the above formula need to change to A7, A8 and so on.

Any help is appreciated.

Asad
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hi asad,

I can vaguely remember trying to make a dynamic range with array formulas and in the end just restored to do doing it cell-by-cell which as you only have 24 isn't an issue in this case:

Code:
Option Explicit
Sub Macro1()

    Dim lngMyRow As Long
    
    Application.ScreenUpdating = False
    
    For lngMyRow = 6 To 29
        Range("C" & lngMyRow).FormulaArray = "=ROUND($J$1*SUM(IF($P$6:$P$293=A" & lngMyRow & ",IF(MONTH($Q$6:$Q$293)=MONTH($E$1),$R$6:$R$293))),0)"
    Next lngMyRow
    
    Application.ScreenUpdating = True

End Sub

I'd be glad to know if there's a more efficient way :)

Regards,

Robert
 
Upvote 0
I am unable to open the link sent by Marcelo.
Is there another way to check it out?
 
Upvote 0
That link basically shows 2 methods to do what you want.

1) Loop every cells you want to enter the formula in, incrimenting the reference A6 to A7 to A8 as it goes.
This is the method shown by Trebor

2) Enter the formula in only the first cell, then Fill it Down
For this method, try
Rich (BB code):
Range("C6").FormulaArray = "=ROUND($J$1*SUM(IF($P$6:$P$293=A6,IF(MONTH($Q$6:$Q$293)=MONTH($E$1),$R$6:$R$293))),0)"
Range("C6:C29").FillDown
 
Upvote 0
Hi asad,

I can vaguely remember trying to make a dynamic range with array formulas and in the end just restored to do doing it cell-by-cell which as you only have 24 isn't an issue in this case:

Code:
Option Explicit
Sub Macro1()

    Dim lngMyRow As Long
    
    Application.ScreenUpdating = False
    
    For lngMyRow = 6 To 29
        Range("C" & lngMyRow).FormulaArray = "=ROUND($J$1*SUM(IF($P$6:$P$293=A" & lngMyRow & ",IF(MONTH($Q$6:$Q$293)=MONTH($E$1),$R$6:$R$293))),0)"
    Next lngMyRow
    
    Application.ScreenUpdating = True

End Sub

I'd be glad to know if there's a more efficient way :)

Regards,

Robert


Thanks a lot Robert. This also worked perfect.
 
Upvote 0

Forum statistics

Threads
1,214,947
Messages
6,122,411
Members
449,081
Latest member
JAMES KECULAH

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