I'm working on a macro that will search a List sheet for different counties and then paste the entire row onto the current sheet. I have a worksheet for each person (named Mark, John, etc.) and each person is assigned several counties. Mark has three counties, listed in cells J1:L1, which I've named as a range (MyCounties). I need a macro that will look through Sheet "List" column "I" for each of those counties and copy the entire row onto Sheet "Mark" starting at "A4". I'm using a modified macro I found on here, but I must be doing something wrong. It is currently giving me an error "Application defined or object defined error" in regards to Set Rng = Sheets("List").Range([I4], Range("I" & Rows.Count).End(xlUp))
Sub NewSheetData()
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Dim Rng As Range, rCell As Range
Set Rng = Sheets("List").Range([I4], Range("I" & Rows.Count).End(xlUp))
For Each rCell In Range("MyCounties")
On Error Resume Next
With Rng
.AutoFilter , field:=1, Criteria1:=rCell.Value
.Offset(1).SpecialCells(xlCellTypeVisible).EntireRow.Copy _
Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
.AutoFilter
End With
On Error GoTo 0
Next rCell
Application.EnableEvents = True
End Sub
Sheets("List").
in front of the secondRange
in that line. – Scott CranerSet Rng = Sheets("List").Range([I4], Sheets("List").Range("I" & Rows.Count).End(xlUp))
I'm still getting the same error. – user4907546[I4]
in quotes and not bracketsSet Rng = Sheets("List").Range("I4", Sheets("List").Range("I" & Sheets("List").Rows.Count).End(xlUp))
– Scott CranerMyCounties
is a named range on the Mark worksheet, what is the named range on the John worksheet? Are these named ranges with worksheet-level scope? – user4039065