|
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False '关闭屏幕涮新
ActiveSheet.AutoFilterMode = False '取消筛选状态
Dim r1 As Integer, r2 As Integer, sh As String
Set sh1 = Sheets("数据源")
sh1.AutoFilterMode = False '取消筛选状态
Rows("3:3").AutoFilter '表头筛选状态
sh = ActiveSheet.Name
Range("AR3").Value = ComboBox1.Value
Sheets("参数表").Range("AH2").Value = ComboBox1.Value
ReDim rr(1 To 3, 1 To 2)
For i = 1 To 3
If Me.Controls("combobox" & i).Text <> "" Then
m = m + 1
rr(m, 1) = Me.Controls("combobox" & i).Text
rr(m, 2) = i
End If
Next i
If m = "" Then MsgBox "请选择筛选条件!": Exit Sub
With sh1
r = .Range("B65536").End(xlUp).Row
ar = .Range("a1:s" & r)
End With
Dim arr()
ReDim arr(1 To UBound(ar), 1 To 1)
For i = 3 To UBound(ar)
sl = 0
For s = 1 To m
mc = rr(s, 1)
lh = rr(s, 2)
If Trim(ar(i, lh)) = Trim(mc) Then
sl = sl + 1
End If
Next s
If sl = m Then
If Trim(ar(i, 19)) = sh Then
n = n + 1
arr(n, 1) = ar(i, 7)
End If
End If
Next i
If n = "" Then MsgBox "没有符合条件的数据!": Exit Sub
With Sheets("参数表")
RS = Cells(Rows.Count, "ah").End(xlUp).Row
.Range("AH2:AH" & RS) = Empty
.[AH2] = Me.ComboBox1.Text
.[AH3].Resize(n, 1) = arr
End With
r2 = Range("C65536").End(xlUp).Row '最后一个不为空的单元格所在的行
Range("AR4:AR" & r2) = "=IFERROR(VLOOKUP(C4,参数表!AH:AH,1,0),0)"
Range("A3:AR" & r2).AutoFilter Field:=44, Criteria1:="<>0"
MsgBox "筛选出" & n & "行数据!"
Application.ScreenUpdating = True '打开屏幕涮新
End Sub |
评分
-
1
查看全部评分
-
|