|
楼主 |
发表于 2024-6-3 18:19
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Option Compare Text
Private Sub CommandButton1_Click() '数组法
Dim arr, f(1 To 9) As Boolean, i&, j&, m&, t
t = Range("A1").CurrentRegion
If UBound(t) = 1 Then Exit Sub '7个条件至少选择了1个才查询
For i = 1 To 9
If Len(t(2, i)) Then f(i) = True
Next
Range("A5:I" & Rows.Count).ClearContents
arr = Sheets("商品库").Range("A1").CurrentRegion
For i = 2 To UBound(arr)
If ((f(1) And InStr(arr(i, 1), t(2, 1))) > 0 Or Not f(1)) _
And ((f(2) And InStr(arr(i, 2), t(2, 2))) > 0 Or Not f(2)) _
And ((f(3) And InStr(arr(i, 3), t(2, 3))) > 0 Or Not f(3)) _
And ((f(4) And InStr(arr(i, 4), t(2, 4))) > 0 Or Not f(4)) _
And ((f(5) And InStr(arr(i, 5), t(2, 5))) > 0 Or Not f(5)) _
And ((f(6) And InStr(arr(i, 6), t(2, 6))) > 0 Or Not f(6)) _
And ((f(7) And InStr(arr(i, 7), t(2, 7))) > 0 Or Not f(7)) _
And ((f(8) And InStr(arr(i, 8), t(2, 8))) > 0 Or Not f(8)) _
And ((f(9) And InStr(arr(i, 9), t(2, 9))) > 0 Or Not f(9)) Then
m = m + 1
For j = 1 To 9
arr(m, j) = arr(i, j)
Next
End If
Next
If m Then [a5].Resize(m, 9) = arr
m = 0
arr = Sheets("商品库2").Range("A1").CurrentRegion
For i = 2 To UBound(arr)
If ((f(1) And InStr(arr(i, 1), t(2, 1))) > 0 Or Not f(1)) _
And ((f(2) And InStr(arr(i, 2), t(2, 2))) > 0 Or Not f(2)) _
And ((f(3) And InStr(arr(i, 3), t(2, 3))) > 0 Or Not f(3)) _
And ((f(4) And InStr(arr(i, 4), t(2, 4))) > 0 Or Not f(4)) _
And ((f(5) And InStr(arr(i, 5), t(2, 5))) > 0 Or Not f(5)) _
And ((f(6) And InStr(arr(i, 6), t(2, 6))) > 0 Or Not f(6)) _
And ((f(7) And InStr(arr(i, 7), t(2, 7))) > 0 Or Not f(7)) _
And ((f(8) And InStr(arr(i, 8), t(2, 8))) > 0 Or Not f(8)) _
And ((f(9) And InStr(arr(i, 9), t(2, 9))) > 0 Or Not f(9)) Then
m = m + 1
For j = 1 To 9
arr(m, j) = arr(i, j)
Next
End If
Next
'If m Then Cells(Rows.Count, 1).End(3).Offset(1).Resize(m, 9) = arr
If m Then Cells(Rows.Count, 1).End(3).Offset(1).Resize(m, 9) = arr
If m Then Cells(Rows.Count, 1).End(xlUp).Offset(1).Resize(m, 9) = arr
End Sub
用这个能不能修改? |
|