Check if this works: *With ActiveWorkbook.Sheets(****CStr(cell.Value)****).Range("Master_Data")*.
Run-time error '9' subscript out of range
First, I am not a programmer! I copied a VBA code found online and modified it to fit my data. The scripts worked fine when I applied to a file using dummy data; however, when I copied to my real data file, I get the "run-time error '9' subscript out of range" error message. Here is the VBA code I'm using...
Sub SplitandFilterSheet()
'Step 1 - Copy Sheet
'Step 2 - Filter by Department and delete rows not applicable
'Step 3 - Loop until the end of the list
Dim Splitcode As Range
Sheets("Master").Select
Set Splitcode = Range("Dept_Split_Code")
For Each cell In Splitcode
Sheets("Master").Copy After:=Worksheets(Sheets.Count)
ActiveSheet.Name = cell.Value
With ActiveWorkbook.Sheets(cell.Value).Range("Master_Data")
.AutoFilter Field:=22, Criteria1:="<>" & cell.Value, Operator:=xlFilterValues
.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End With
ActiveSheet.AutoFilter.ShowAllData
Next cell
End Sub
The error occurs "With ActiveWorkbook.Sheets(cellValue).Range("Master_Data")
I've verified with range names are correct. Any assistance is greatly appreciated.
As typical, time is of the essence!
Thanks - Diane