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

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
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,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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