Formula Array (CSE) in VBA

Roderick_E

Well-known Member
Joined
Oct 13, 2007
Messages
2,051
Hi there all. I know how to do a sheet1.cells(x,y).formularray = "=formula" but I'm trying to accomplish something a bit different.

Using INDEX MATCH within VBA I can return a simple single column match, such as:

Code:
sheet1.cells(x,y) = application.index(sheet2.range("A:A"),application.match(string,sheet2.range("B:B"),0),1)

However, what if I wanted do match multiple criteria via VBA? In a formula you would do something like the following but requires control+shift+enter {...}:

Code:
=index(sheet2.range("A:A"),match(string1&string2,sheet2.range("B:B")&sheet2.range("C:C"),0 ),1)

This would return a string from column A if string1&string2 matching together in columns B and C.

QUESTION: How do I make this work in VBA?
Excel 2003-2010 in use
Thanks
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Couldn't you just use an if then statement in VBA?

Something like...

Code:
If Range("B1") = string1 And Range("C1") = string2 then
    ' return A
end if

I am not sure of the exact implementation but I hope that helps
 
Upvote 0
Well, the exact row in the range is unknown. I could use a loop For X statement but it is extremely slow processing
 
Upvote 0
This might be more helpful

Code:
If Sheet1.Cells(intRow, "B") = string1 And Sheet1.Cells(intRow, "C") Then
    Sheet1.Cells(intRow, intCol) = Cells(intRow, "A")
End If
 
Upvote 0
yeah, the .formularray solution inserts a formula into the cell, not really what I wanted to do. I could probably do something like that and then turn it into a string but kind of clunky. Thanks for trying to help. I'll keep looking and post here if I find a solution.
 
Upvote 0
Ok, I'm getting closer using EVALUATE
My actual code snippet:
Code:
'match defaults
On Error Resume Next
evalstr = "INDEX(" & "'" & Sheet2.Name & "'!E:E,MATCH(""" & vorgcitystr & """ & """ & vdstcitystr & """ & """ & vorgportstr & """ & """ & vdstportstr & """, '" & Sheet2.Name & "'!A:A" & "&" & "'" & Sheet2.Name & "'!B:B" & "&" & "'" & Sheet2.Name & "'!C:C" & "&" & "'" & Sheet2.Name & "'!D:D,0),1)"
If IsError(Evaluate(evalstr)) = False Then
Sheet3.Cells(i, "g") = Evaluate(evalstr)
End If
Resume Next

Seems like evaluate can't handle too many processes. Anyone have specs?
 
Upvote 0

Forum statistics

Threads
1,216,073
Messages
6,128,644
Members
449,461
Latest member
kokoanutt

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