使用变量我需要选择一个值并存储在变量" str"来自sheet4并在sheet1中搜索。它必须找到甚至它不完全匹配例如,如果一个str =" ABC123"然后它激活sheet1中的单元格,其值为" ABC12345" 我尝试使用以下代码,
Sub Find_First()
Dim FindString As String
Dim Rng As Range
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim ws3 As Worksheet
Dim ws4 As Worksheet
Set ws1 = Sheets("Sheet1")
'Set ws1 = ActiveWorkbook.Worksheets(1)
Set ws2 = Sheets("Sheet2")
Set ws3 = Sheets("Sheet3")
Set ws4 = Sheets("Export")
'FindString = InputBox("Enter a Search value")
FindString = ws4.Range("A1").Value
ws1.Activate
If Trim(FindString) <> "" Then
With Sheets("Sheet1").Range("A:A")
Set Rng = .Find(What:=FindString, _
LookIn:=xlValues, LookAt:=xlWhole, _
MatchCase:=False, _
SearchFormat:=False)
If Not Rng Is Nothing Then
Application.Goto Rng, True
Else
'MsgBox "Nothing found"
End If
End With
End If
End Sub