I cannot find the correct type for my lookup
function in vba.
My Excel formula is as following and works fine.
=IF(INDIRECT("'Enclosure4-Workflow_Structure'!C"&MATCH('Enclosure2-Accesses'!A8;
'Enclosure4-Workflow_Structure'!A:A; 0))="Create";
IF(LOOKUP(2; 1/('Enclosure5-Workflow_Steps'!A:A=INDIRECT("'Enclosure4-Workflow_Structure'!D"
&MATCH('Enclosure2-Accesses'!A8; 'Enclosure4-Workflow_Structure'!A:A; 0)));
'Enclosure5-Workflow_Steps'!D:D) = "Task"; 'Enclosure2-Accesses'!B8; FALSE); FALSE)
The first if-clause works fine for me but the second if-clause contains the lookup
function. This lookup function should come up with "Task"
, therefore I thought I should set the DIM as String
but I constantly receive the error message: "Type mismatch".
The line which throws the error should get the last occurence of a value. This value should correspond to "Task" in the D column.
lOccurence = WorksheetFunction.Lookup(2, 1 / (Enc5.Range("A:A") = Enc4.Cells(MatchCrt, "D").Value), Enc5.Range("D:D"))
I am curious why the above line causes the error. In Excel the line works without problem. Is the line incorrect or is the DIM type (String) incorrect?
My VBA code is:
Public Sub CopyUserAR2Data()
Dim Enc2 As Worksheet
Dim Enc4 As Worksheet
Dim Enc5 As Worksheet
Dim Enc9 As Worksheet
Dim MatchCrt As Double
Dim lOccurence As String
Set Enc2 = Sheets("Enclosure2-Accesses")
Set Enc4 = Sheets("Enclosure4-Workflow_Structure")
Set Enc5 = Sheets("Enclosure5-Workflow_Steps")
Set Enc9 = Sheets("Enclosure9-Dependency")
MatchCrt = WorksheetFunction.Match(Enc2.Cells(9, "A"), Enc4.Range("A:A"), 0)
lOccurence = WorksheetFunction.Lookup(2, 1 / (Enc5.Range("A:A") = Enc4.Cells(MatchCrt, "D").Value), Enc5.Range("D:D"))
If Enc4.Cells(MatchCrt, "C") = "Create" Then
Enc9.Cells(2, 1).Value = lOccurence
End If
End Sub
1 / (Enc5.Range("A:A")
in VBA, nor can you compare an array to a value using=
. You'd have to pass the formula toEvaluate
, or loop through the range. – Rorylookup
function. Can you tell me why I receive the same error message?ar = Evaluate(" =Lookup(2, 1/('Sheet1'!A:A = 'Sheet2'!D2),'Sheet3'!D:D) ")
On MrExcel was practical the same formula which was working for somebody. – Alex_P