A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
The statement Set src = wb.Worksheets("OrigDL") will fail if the workbook referenced by wb does not contain a worksheet named exactly OrigDL. The first thing to verify is which workbook ActiveWorkbook is actually referencing.
Add these lines immediately before the failing statement:
Debug.Print "Active workbook: " & ActiveWorkbook.Name Debug.Print "Workbook path: " & ActiveWorkbook.Path Debug.Print "Worksheet count: " & ActiveWorkbook.Worksheets.Count
You can also list every worksheet name:
Dim ws As Worksheet
For Each ws In wb.Worksheets Debug.Print "[" & ws.Name & "]" Next ws
Then open the Immediate window with Ctrl+G and check whether OrigDL appears exactly as expected. This will also reveal leading or trailing spaces in the worksheet name.
Another potential cause is that ActiveWorkbook is not the workbook you expect. ActiveWorkbook refers to whichever workbook is active when the procedure runs. If OrigDL is in the workbook containing the VBA code, use ThisWorkbook instead:
Set wb = ThisWorkbook Set src = wb.Worksheets("OrigDL")
ThisWorkbook refers specifically to the workbook containing the VBA project, while ActiveWorkbook refers to the workbook currently active in Excel.
If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.
hth
Marcin