|
- Sub Test()
- Dim Arr
- Dim i&, r&
- Dim AA, Sr As String
- On Error Resume Next
- Arr = Sheets("源数据").[A1].CurrentRegion
- r = 2
- With Sheets("查询")
- .Range("A3:E" & Rows.Count).ClearContents
- If .Cells(1, 2) = "" And .Cells(1, 4) = "" Then MsgBox "请输入查询条件"
- If .Cells(1, 2) <> "" And .Cells(1, 4) <> "" Then
- AA = .Cells(1, 2) & "|" & Sheets("查询").Cells(1, 4)
- For i = 2 To UBound(Arr)
- Sr = Arr(i, 1) & "|" & Arr(i, 2)
- If AA = Sr Then
- r = r + 1
- .Cells(r, 2) = Arr(i, 1): .Cells(r, 3) = Arr(i, 2)
- .Cells(r, 4) = Arr(i, 3): .Cells(r, 5) = Arr(i, 4)
- End If
- Next
- Else
- For i = 2 To UBound(Arr)
- If Arr(i, 2) = .Cells(1, 4) Then
- r = r + 1
- .Cells(r, 2) = Arr(i, 1): .Cells(r, 3) = Arr(i, 2)
- .Cells(r, 4) = Arr(i, 3): .Cells(r, 5) = Arr(i, 4)
- End If
- Next
- End If
- End With
- End Sub
复制代码 |
|