Autofill an Array with a Macro

bluedevil

New Member
Joined
Apr 22, 2010
Messages
8
Hi,

I have an array (below) formula that I need to enter into a list of data using a macro.

=MAX(IF($B$2:$B$194=B2,$N$2:$N$194))

The bolded B2 needs to change to match the row that it is entered in.

The forumla I have used to enter the array is:

Range("O2:O" & LR).FormulaArray = "=MAX(IF(R2C2:R" & LR & "C2=RC[-13],R2C14:R" & LR & "C14))"

(LR is a count of the last row with data).

The problem I have is that when I do this the B2 doesn't update as it would when you Autofill. I have recorded the code for Autofill and tried using that, but I get an error message.

At the moment I have a Loop in place that does what I need, however due to the large volumes of data this takes a lot of time. For reference my copde for the loop is:
Do
Row = ActiveCell.Row
ActiveCell.FormulaArray = "=MAX(IF(R2C2:R" & LR & "C2=RC[-13],R2C14:R" & LR & "C14))"
ActiveCell.Offset(1, 0).Select
Loop Until Row = LR


Is there any way I can sort this without using the loop?

Thank you for any help you can give,
Paul
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I got this code to work using autofill so you would not need to incorporate this into a loop.

Code:
Range("O2").FormulaArray = "=MAX(IF(R2C1:R26C1=RC[-14],R2C2:R26C2))"
Range("O2").AutoFill Destination:=Range("O2:O" & LR)

Notice that I am placing the array formula in column "O" and that in the array formula I am using [-14] instead of the [-13] that you had since my customer is in column "A".

Let me know how this works out for you. :)
 
Upvote 0
That is brilliant, not sure what I was doing with the autofill code but that has worked a charm!
Thanks very much.
 
Upvote 0

Forum statistics

Threads
1,215,336
Messages
6,124,329
Members
449,155
Latest member
ravioli44

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