Forum Discussion
Convert index match with multiple criteria into VBA
- Aug 19, 2022
Try this version:
Sub vlkupfromworkingfile() Dim ws As Worksheet Dim wsLastrow As Long Dim r As Long Const sSheet As String = "'C:\Users\hrhquek\Desktop\[working file.xlsx]Sheet1'!" Application.ScreenUpdating = False Application.Calculation = xlCalculationManual Set ws = Sheet1 ws.Range("D:D").EntireColumn.Insert ws.Range("D1").Value = "Remarks" wsLastrow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row 'On Error Resume Next For r = 2 To wsLastrow ws.Range("D" & r).Value = Evaluate("= Index(" & sSheet & "$D$2:$D$5000,MATCH(1,(" & _ sSheet & "$C$2:$C$5000=C" & r & ")*(" & sSheet & "$P$2:$P$5000=P" & r & "),0))") Next r Application.Calculation = xlCalculationAutomatic Application.ScreenUpdating = True End Sub
HansVogelaar , the code works perfectly. thanks and appreciate the assist!
hi HansVogelaar , i tried amending the respective filepath below to where it was saved:
Const sSheet As String = "'C:\Users\hrhquek\Desktop\report\[640910690606641710_JantoJul(working).xlsm]Sheet1'!"
and it keeps populating #value! despite there is no change in the format. File path is gotten from the cmd which should not be invalid.
For example, the source file (containing the code) contains data from Jan22 to Jul22.
The new file contains data from Jan22 to Aug22. Therefore, i would copy the code from the source file and paste it into the new file so as to execute a lookup from the source file.
Therefore, this results in the cell to populates #value!
- hrh_dashAug 23, 2022Iron ContributorAlright noted on this. Thanks and appreciate the advice
- HansVogelaarAug 22, 2022MVP
Thank you. The problem is that the string to evaluate has become longer than the maximum length of 255, because of the long filename. Can you shorten the name to for example JantoJul.xlsm ?
- hrh_dashAug 22, 2022Iron Contributor
Hi HansVogelaar , attaching both file.
aug22 - copy workbook will be taking reference from 640910690606641710_JantoJul(working)_Copy workbook
Hence, the macro from 640910690606641710_JantoJul(working)_Copy workbook will be copied into aug22 - copy workbook.
- HansVogelaarAug 22, 2022MVP
I'm afraid it's impossible for me to know what is wrong without seeing the workbooks.