我有多行的Excel工作表,我需要根据单元格值过滤行。
此行停止
Set vlRowRange = .Rows("" & vlRow - 1 & ":" & vlRow + 3 & "")
完整代码:
Private Sub Filter_Rows(myRange As String, xSheet As String)
Dim vlCell As Range
Dim vlRange As Range
Dim vlRowRange As Variant
Dim vlRow As Integer
With Sheets(xSheet)
Set vlRange = .Range(myRange)
End With
For Each vlCell In vlRange
vlRow = vlCell.EntireRow.Row
With Sheets(xSheet)
Set vlRowRange = .Rows("" & vlRow - 1 & ":" & vlRow + 3 & "")
End With
If vlCell.Value = Me.sub_filter_1.Value Then
vlRowRange.EntireRow.Hidden = False
Else
vlRowRange.EntireRow.Hidden = True
End If
Next vlCell
End Sub
答案 0 :(得分:0)
.Worksheet对象的对象只接受一个整数作为参数。您正试图将范围传递给它。尝试使用范围对象。
答案 1 :(得分:0)
我设法像这样完成它
Dim vlRange, vlCell, vlRowRange As Range
Dim vlSheet As Worksheet
Dim vlRow As Integer
Set vlSheet = Worksheets(Me.Name)
With vlSheet
Set vlRange = .Range("A1:A10000")
End With
For Each vlCell In vlRange
If vlCell.Value = Me.sub_filter_1.Value Then
vlRow = vlCell.EntireRow.Row
Set vlRowRange = Sheet25.Rows("" & vlRow - 1 & ":" & vlRow + 3 & "")
vlRowRange.EntireRow.Hidden = False
End If
Next vlCell