Error 9 — “Subscript out of range” — means the code asked for something by name or by number and that thing is not there: a worksheet with a slightly different name, an array index past the end, a workbook that isn't open. VBA is rarely wrong about this. Something the code believes exists, doesn't.
Every name or index used to pull an item out of a collection — Worksheets("Report"), arr(7), Workbooks("Data.xlsx") — is a “subscript.” When no item matches, VBA raises error 9 rather than returning nothing. Ninety percent of cases are a name that doesn't match exactly, or a count that isn't what the code assumed.
"Report ") are invisible and fatal.Workbooks("name.xlsx") only works for open workbooks, and the name must include the extension exactly as shown in the title bar.Split() or filter result has fewer parts than expected — the delimiter wasn't in the text.For Each ws In Worksheets: Debug.Print "[" & ws.Name & "]": Next — brackets expose hidden spaces.Dim ws As Worksheet
On Error Resume Next
Set ws = Worksheets("Report")
On Error GoTo 0
If ws Is Nothing Then MsgBox "Sheet 'Report' not found": Exit Sub
For i = LBound(arr) To UBound(arr) instead of assuming a size, especially with arrays built from ranges or Split().The mismatch is dynamic: the name is being built while the macro runs — from a cell, a date, a file listing. Print the built name with Debug.Print right before the failing line and compare it against what actually exists at that moment. Nine times out of ten, the difference is a space, a date format, or a renamed tab.
Does error 9 mean the file is corrupted? No. It means the macro couldn't find something it referenced. The workbook itself is fine.
Why did the macro work yesterday and fail today? Something it references changed: a sheet was renamed, a file was saved under a new name or not opened, or the data shrank (fewer rows means a smaller array than the loop expects).