Search code examples
excelvbamatchevaluate

VBA Evaluate - Match


I have a problem with my codes below, As you can see, I am trying to find the row value of a search. I have 3 different criteria ( they are defined before ) and 3 different ranges ( also defined before ). But I cannot find the rows unfortunately.

Here you can see the codes;

Gorev = Worksheets(WS_All).Cells(p, o).Value
SlideNo = Worksheets(WS_All).Cells(p, 34).Value
Egitim_Adi = Worksheets(WS_All).Cells(2, 3).Value
Check1 = Worksheets(j_WS).Range("A:A")   'Egitim_Adi Kontrolü için'
Check2 = Worksheets(j_WS).Range("B:B") 'SlideNo Kontrolü için'
Check3 = Worksheets(j_WS).Range("C:C")  'Gorev Kontrolü için'

Satir_bul = Evaluate("=Match(" & Egitim_Adi & " & " & SlideNo & " & " & Gorev & ", Check1 & Check2 & Check3, 0)")

I am open to any suggestion..


Solution

  • You have a whole heap of problems there. WorksheetFunction.Match is not going to work because you are trying to replicate an array formula so Evaluate is definitely a better bet, but you need to construct the correct formula string for it. Unless you know whether the contents of the three cells will always be text or numbers, it is easier to just use cell addresses than to worry about enclosing the values in quotes:

    Gorev = Cells(p, o).address
    SlideNo = Cells(p, 34).address
    Egitim_Adi = Cells(2, 3).address
    
    Satir_bul = Worksheets(WS_All).Evaluate("=Match(" & Egitim_Adi & "&" & SlideNo & "&" & Gorev & ", '" & j_WS & "'!A:A&'" & j_WS & "'!B:B&'" & j_WS & "'!C:C, 0)")
    

    If you can limit the ranges rather than using entire columns, you'll get better performance too.