When using a WITH statement in a macro can I reference a Sheet in another Workbook?
Tried it but couldn't get it to work.
Also, when coding the WITH statement why must I use Sheet1, Sheet2, ... as a reference instead of a Sheet's actual name? Tried it but couldn't get it to work.
Example Code (works fine as coded):
With Sheet1
On Error Resume Next
.AutoFilterMode = False
If Range("A2") = "all" Then
.Range("A8:Q65").AutoFilter Field:=1, Criteria1:="*"
Else
.Range("A8:Q65").AutoFilter Field:=1, Criteria1:=Sheet2.[A2] & "*"
End If
.Range("A8:Q" & .Cells(Rows.Count, "A").End(xlUp).Row).Offset(1, 0).SpecialCells(xlCellTypeVisible).Copy
Sheet2.[A8].PasteSpecial xlValues
.ShowAllData
End With
Tried it but couldn't get it to work.
Also, when coding the WITH statement why must I use Sheet1, Sheet2, ... as a reference instead of a Sheet's actual name? Tried it but couldn't get it to work.
Example Code (works fine as coded):
With Sheet1
On Error Resume Next
.AutoFilterMode = False
If Range("A2") = "all" Then
.Range("A8:Q65").AutoFilter Field:=1, Criteria1:="*"
Else
.Range("A8:Q65").AutoFilter Field:=1, Criteria1:=Sheet2.[A2] & "*"
End If
.Range("A8:Q" & .Cells(Rows.Count, "A").End(xlUp).Row).Offset(1, 0).SpecialCells(xlCellTypeVisible).Copy
Sheet2.[A8].PasteSpecial xlValues
.ShowAllData
End With