自5个小时以来,我一直在努力应对以下代码,我希望对此进行扩展。我只是想通过输入框模拟内置的ctrl + F搜索工具,添加该功能以在查找名称(字母而不是数字)时留在行/列(ActiveCell)中。
工作代码:
Sub Jarvis()
Dim sResult As String
On Error Resume Next
sResult = InputBox("Bitte Produktname angeben")
If IsNumeric(sResult) Then 'row
Cells(sResult, ActiveCell.Column).Select
Else 'Select column - Here I want to add a way to search for names/values and to jump to them, while staying in the current column - Unfortunately didn't find the suiting command
Cells(ActiveCell.Row, sResult).Select
End If
End Sub
非工作代码:
Sub Jarvis2()
Dim sResult As String
On Error Resume Next
sResult = InputBox("Bitte Produktname angeben")
If IsNumeric(sResult) Then 'row
Cells(sResult, ActiveCell.Column).Select
Else 'Select column - Here I want to add a way to search for names/values and to jump to them, while staying in the current column - Unfortunately didn't find the suiting command
Columns("AW2:JZ5", sResult).Select
End If
End Sub
任何专业人士都可以帮助我吗?
谢谢您对PEH的帮助。
这是我的解决方法:
Sub Jarvis()
Dim word, cellRange, firstAddress, c, FindNext, BottomRight As String
word = InputBox("insert search term", "")
If word = "" Then Exit Sub
cellRange = "aw2:ku5"
'change search range
With ActiveSheet.Range(cellRange)
Set c = .Find(word)
If Not c Is Nothing Then
firstAddress = c.Address
Do
Range(c.Address, ActiveCell).Select
With Selection
BottomRight = .Cells(.Rows.Count, .Columns.Count).Select
End With
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
End Sub
如果任何专业人士找到更有效的方法,请更正它。