0
下面的代碼有助於搜索在單元格K8
中輸入的值並返回與其相關的值。我需要幫助搜索多個值,需要搜索範圍K8:K30
中輸入的所有值,並且需要顯示與它們相關的記錄。使用excel vba搜索多個值
Sub finddata()
Dim emstring As String
Dim finalrow As Integer
Dim i As Integer
Sheets("Sheet1").Range("P3:X37").ClearContents
emstring = Sheets("sheet1").Range("K8").Value
finalrow = Sheets("Sheet1").Range("A6000").End(xlUp).Row
For i = 2 To finalrow
If Cells(i, 2) = emstring Then
Range(Cells(i, 1), Cells(i, 3)).Copy
Range("P6000").End(xlUp).Offset(1, 0).PasteSpecial xlPasteFormulasAndNumberFormats
End If
Next i
End Sub