MarioMacias
New Member
- Joined
- Dec 1, 2017
- Messages
- 3
Hi! I've using cycle macros for searching in each column certain value and then comparing values in adjacent columns in order to get values to show or similar matters
At this moment I found out that there is a way to call formulas from vba code via Application.WorksheetFormulas
and at the same time I found the Match+Index formulas for multiple criteria by arrange {}
Is there a way to use the ArrayFormulas from VBA??
My idea is something like the one as follow...
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$D$1" Or Target.Address = "$D$2" Then
If ActiveSheet.Range("D1") = "" Or ActiveSheet.Range("D2") = "" Then
MsgBox = ("Complete data before start")
Else
'criteria to search
Val1 = ActiveSheet.Range("D1").Value
Val2 = ActiveSheet.Range("D2").Value
'columns to search each value
RangeVal1 = ActiveSheet.Range("A:A")
RangeVal2 = ActiveSheet.Range("B:B")
Matrix = ActiveSheet.Range("A:C")
'My problem is at the formula assigned to Result that only works when it is in an array "{=index...}"
Result = Application.WorksheetFunction.Index(Matrix, Application.WorksheetFunction.Match(Val1 & Val2, RangeVal1 & RangeVal2, 0), 3)
ActiveSheet.Range("D3").Value = Result
End If
End If
End Sub
Any ideas will be welcome
Best regards!
At this moment I found out that there is a way to call formulas from vba code via Application.WorksheetFormulas
and at the same time I found the Match+Index formulas for multiple criteria by arrange {}
Is there a way to use the ArrayFormulas from VBA??
My idea is something like the one as follow...
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$D$1" Or Target.Address = "$D$2" Then
If ActiveSheet.Range("D1") = "" Or ActiveSheet.Range("D2") = "" Then
MsgBox = ("Complete data before start")
Else
'criteria to search
Val1 = ActiveSheet.Range("D1").Value
Val2 = ActiveSheet.Range("D2").Value
'columns to search each value
RangeVal1 = ActiveSheet.Range("A:A")
RangeVal2 = ActiveSheet.Range("B:B")
Matrix = ActiveSheet.Range("A:C")
'My problem is at the formula assigned to Result that only works when it is in an array "{=index...}"
Result = Application.WorksheetFunction.Index(Matrix, Application.WorksheetFunction.Match(Val1 & Val2, RangeVal1 & RangeVal2, 0), 3)
ActiveSheet.Range("D3").Value = Result
End If
End If
End Sub
Any ideas will be welcome
Best regards!