我有一个搜索工作表,可用于搜索其他工作表。该宏有效,但是我无法在两个列中搜索相同的单词。我厌倦了OR而不是And,但那没有用。我也尝试添加另一个整数,但是那也不起作用。这是我宏的一些内容...基本上我想在第6列和第7列中搜索相同的单词。
Sub Searchcustomer()
Dim audit As String
Dim saudit As String
Dim finalrow As Long
Dim i As Long
Set msheet = Sheet11
Set ssheet = Sheet10
audit = ssheet.Range("B8").Value
msheet.Select
finalrow = msheet.Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To finalrow
If IIf(audit <> "", Cells(i, 6) = audit, True) Then
msheet.Range(msheet.Cells(i, 1), msheet.Cells(i, 9)).Copy
msheet.Range(msheet.Cells(i, 1), msheet.Cells(i, 9)).Copy Destination:=ssheet.Range("A100").End(xlUp).Offset(1, 0).Resize(1, 9)
End If
Next i
ssheet.Select
ssheet.Range("B3").Select
End Sub
答案 0 :(得分:2)
For i = 1 To finalrow
With msheet.rows(i)
If IIf(audit <> "", (.Cells(6) = audit Or .Cells(7) = audit), True) Then
.Cells(1).Resize(1, 9).Copy _
Destination:=ssheet.Range("A100").End(xlUp).Offset(1, 0)
End If
End With
Next i