我正在尝试命名范围并将其设置为等于变量,我认为有更好的方法可以省略.activate,因为如果用户位于不同的工作表上,它会中断。有关如何解决它的任何想法?
Sub Auto_Filter()
Dim RNG As Range
Dim Open_Jobs_Report As Worksheet
Set Open_Jobs_Report = ThisWorkbook.Sheets("Open Jobs Report")
Dim Calculations As Worksheet
Set Calculations = ThisWorkbook.Sheets("Calculations")
Dim PersonResponsible As Range
Dim Violations As Range
With Sheets("Open Jobs Report")
Set RNG = .Range("A1", .Cells(.Cells(.Rows.Count, "A").End(xlUp).Row, .Cells(1, .Columns.Count).End(xlToLeft).Column))
RNG.AutoFilter Field:=19, Criteria1:="<>"
Cells.Find(What:="Person Responsible").Activate ' <= Here
Range(Selection, Selection.End(xlDown)).Name = "Range1"
Set PersonResponsible = Range("Range1")
Cells.Find(What:="Violations").Activate ' <= And here
Range(Selection, Selection.End(xlDown)).Name = "Range2"
Set Violations = Range("Range2")
End With
Open_Jobs_Report.Range(PersonResponsible).Value = Calculations.Range("A1:A3").Value
ActiveSheet.ListObjects(1).AutoFilter.ShowAllData
End Sub