想用VBA查询,满足条件的结果都能得到正确值,不满足条件的为什么是第一条结果?
代码如下:
Sub 查询()
Dim rng As Range, ends&, i&, k&
[f3:i999].Clear
ends = Sheets(4).Columns(1).Find("*", SearchDirection:=xlPrevious).Row
For Each rng In Range("a2:a" & ends)
i = i + 1
If rng Like [g1] Then
[a1:d1].Offset(i).Copy Cells(k + 2, "f")
k = k + 1
End If
Next
End Sub
如何修改代码能让不满足查询条件的为空呢?
代码如下:
Sub 查询()
Dim rng As Range, ends&, i&, k&
[f3:i999].Clear
ends = Sheets(4).Columns(1).Find("*", SearchDirection:=xlPrevious).Row
For Each rng In Range("a2:a" & ends)
i = i + 1
If rng Like [g1] Then
[a1:d1].Offset(i).Copy Cells(k + 2, "f")
k = k + 1
End If
Next
End Sub
如何修改代码能让不满足查询条件的为空呢?