Update Array formula using Macro

payney

New Member
Joined
Jan 9, 2007
Messages
5
I have created the below formula because I have multiple lookup criteria on an Excel table; however, in order to make it work, I have to individually go into each cell and press Ctrl+Shift+Enter. When I tried to create a macro For Each Cell in Selection every cell in the selection returned the same value, as if it was looking up the same criteria.

=SUM(IF('Data table - actual'!$A:$A=('Actual formula'!B$4&'Actual formula'!$A5),'Data table - actual'!$E:$E))

Does anyone know how to create a macro to individually update each cell within a formula?

Many thanks


Michael
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
It sounds like you were setting the Formula property instead of the FormulaArray property. Change your code and try again.
 
Upvote 0
Glen

Thanks for your reply. I'm a little new to this, so could you explain what you mean in a bit more detail.


Many thanks

Michael
 
Upvote 0
You said:
...When I tried to create a macro For Each Cell in Selection every cell in the selection returned the same value, as if it was looking up the same criteria....
Well, in that macro you must have used the Formula property to set up the formulas. You should have used the FormulaArray property.
 
Upvote 0
Probably would have helped if i showed you the code!

For Each cell In Selection
Selection.FormulaArray = _
"=SUM(IF('Data table - actual'!C1=('Actual formula'!R4C&'Actual formula'!RC1),'Data table - actual'!C5))"
Next


So, when I press "go" on the macro, all the formula becomes the "SUM(IF)" formula stated above. How do ctrl+shift+enter the formula currently in the cell without replacing it with the formula above?
 
Upvote 0
You have an error in your code:
Rich (BB code):
For Each cell In Selection
cell.FormulaArray = _
"=SUM(IF('Data table - actual'!C1=('Actual formula'!R4C&'Actual formula'!RC1),'Data table - actual'!C5))"
Next
 
Upvote 0
Glen, that it absolutely fantastic!

Thank you eversomuch for your help. Unfortunately, I have quite a few cells to update, which takes quite a while using this code. Don't suppose you have anymore great ideas on how to quicken it up?


Many thanks


Michael
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,848
Members
452,948
Latest member
UsmanAli786

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