Run time error '1004' Unable to get the Match propertyof the WorksheetFunction class

前端 未结 6 1317
悲&欢浪女
悲&欢浪女 2021-01-17 01:29

In my macro, I have the following code :

i = Application.WorksheetFunction.Match(str_accrual, Range(Selection, Selection.End(xlToRight)), 0)
6条回答
  •  北荒
    北荒 (楼主)
    2021-01-17 02:16

    tons of posts on this error but no solution as far as I read the posts. It seems that for various worksheet functions to work, the worksheet must be active/visible. (That's at least my latest finding after my Match() was working randomly for spurious reasons.)

    I hoped the mystery was solved, though activating worksheets for this kind of lookup action was a pain and costs a few CPU cycles.

    So I played around with syntax variations and it turned out that the code started to work after I removed the underscore line breaks, regardless of the worksheet being displayed. <- well, for some reason I still had to activate the worksheet :-(

    'does not work

    'Set oCllHeader = ActiveWorkbook.Worksheets("Auswertung").Cells(oCllSpielID.Row, _
                        Application.Match( _
                            strValue, _
                            ActiveWorkbook.Worksheets("Auswertung").Range( _
                                oCllSpielID, _
                                ActiveWorkbook.Worksheets("Auswertung").Cells(oCllSpielID.Row, lastUsedCellInRow(oCllSpielID).Column)), _
                                0))
    

    'does work (removed the line breaks with underscore for readibility) <- this syntax stopped working later, no way around activating the worksheet :-(

    Set oCllHeader = ActiveWorkbook.Worksheets("Auswertung").Cells(oCllSpielID.Row, Application.Match(strValue, ActiveWorkbook.Worksheets("Auswertung").Range(oCllSpielID, ActiveWorkbook.Worksheets("Auswertung").Cells(oCllSpielID.Row, lastUsedCellInRow(oCllSpielID).Column)), 0))
    

    In the end I am fretting running into more realizations of this mystery and spending lots of time again.

    cheers

提交回复
热议问题