VBA- Array Formula with Dynamic Last Cell

willwill88

New Member
Joined
Dec 8, 2011
Messages
5
Hi,

I'm trying to make an array formula with vba where the logical test stops at the last row. I'm hoping this will speed up the macro instead of scanning a whole column C:C for example, which could have 2,000 - 600,000+ rows.

Sheet 1 has the data
Sheet 4 is where im putting the fomula

I was hoping this forumla would work but no dice. Any help would be appreciated.

Selection.FormulaArray = _
"=MAX(IF(C2=(Sheet1(C2:C & LastRow),(Sheet1.Range(U2:U & LastRow),""""))"


Code:
Sheets(1).Activate
LastCol = Cells(2, Columns.Count).End(xlToLeft).Column
LastRow = Cells(Rows.Count, "B").End(xlUp).Row
Sheets(4).Activate
Range("AI2").Select

Code works but is slow
Selection.FormulaArray = _
"=MAX(IF(RC[-32]='Reservation Details By Date'!C[-32],'Reservation Details By Date'!C[-14],""""))"

'Error with this code
Selection.FormulaArray = _
"=MAX(IF(C2=(Sheet1(C2:C & LastRow),(Sheet1.Range(U2:U & LastRow),""""))"

'Error with this code
Selection.FormulaArray = _
"=MAX(IF(C[-32]=(Sheet1(C[-32] & LastRow),(Sheet1.Range(C[-14] & LastRow),""""))"
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
You could do the same with named ranges and then don't need VBA:

ColA is:
=OFFSET(Sheet2!$A$1,1,0,COUNTA(Sheet2!$A:$A)-1,1)

ColB is:
=OFFSET(Sheet2!$B$1,1,0,COUNTA(Sheet2!$B:$B)-1,1)

So here are the formulas:

Excel 2003
ABC
1ColAColBFormula
2B810
3C610
4B410
5E49
6A59
7E89
8B810
9D110
10E19
11E39
12D910
13E79
14A89
15B410
16B510
17A39
18B110
19B910
20D510
21B1010
22D1010
23B910
24E99
25A89
26A99
27E49
28C210
29D610
30C1010
31C710
Sheet2
Cell Formulas
RangeFormula
C2{=MAX(IF(A2=ColA,ColB))}
Press CTRL+SHIFT+ENTER to enter array formulas.
Named Ranges
NameRefers ToCells
ColA=OFFSET(Sheet2!$A$1,1,0,COUNTA(Sheet2!$A:$A)-1,1)
ColB=OFFSET(Sheet2!$B$1,1,0,COUNTA(Sheet2!$B:$B)-1,1)


No need for VBA.
 
Upvote 0

Forum statistics

Threads
1,223,632
Messages
6,173,472
Members
452,516
Latest member
archcalx

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