Excel VBA - search box for any value but to stay in row/ column

Twiino

New Member
Joined
May 17, 2020
Messages
2
Office Version
  1. 365
Platform
  1. MacOS
Hello Mr. Excel Community

Since 5 hours I am struggling with the following code, which I'd love to expand.
I simply want to mimic the built in ctrl + F search tool via an Input Box, adding the feature to stay in row/column (ActiveCell) while looking for the name (letters not numbers).

VBA Code:
Sub Jarvis()

Dim sResult As String

  On Error Resume Next
  
  sResult = InputBox("")
  
  If IsNumeric(sResult) Then 'Select 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••••ˇˇˇˇ

Could anyone of the pros help me out?

Cheers
Matteo
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
I think this will do what you want.
Alternalty, you could select the whole column and use Excel's Find. Probably be the same number of mouse clicks.
 
Upvote 0
@mikeerickson: Thank you for your help.

Here is my solution:

VBA Code:
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

If you have a more efficient way, please correct my code.

Cheers
Matteo
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top