Hello. I have this code that matches up data from one workbook to another and pastes in information from one to another. However, one of the workbooks now has a different name format and it will no longer recognize it. Gives me the object variable error. The old name was in the format of DspPickOrder-2020-current date. The new one is named current date-DSP-PickOrder. Here is the code. The line it gives me the error is If InStr(Workbooks(i).Name, "Pickorder"). The code will no longer recognize the "Pickorder name in the new one. Here is the main part of the code. Thanks to anyone willing to help.
Sub Match() For Each w In Workbooks If UCase(w.Name) Like UCase("*Pick*order*") Then Windows(w.Name).Activate Exit For End If Next w Dim dsp As Workbook 'DISPATCH Dim crtx As Workbook 'CORTEX Dim rngCTX As Range 'CORTEX RANGE Dim sq As Range 'SPARE RANGE Dim PO As Worksheet 'PICKORDER SHEET Dim i As Long 'ITERATION 'FIND PICKORDER WORKBOOK & SHEET For i = 1 To Workbooks.Count If InStr(Workbooks(i).Name, "Pickorder") Then Set dsp = Workbooks(i) End If Next i For i = 1 To dsp.Worksheets.Count If InStr(Worksheets(i).Name, "Pickorder") Then Set PO = dsp.Sheets(Worksheets(i).Name) End If Next i