VBA code find text and move cursor to that location

m242

New Member
Joined
Aug 9, 2020
Messages
13
Office Version
  1. 2019
Platform
  1. Windows
Hi specialists,

Goal:
From a pushbutton I try to search for the word 'AMS' in a specific colomn and if found, move the cursor to that specific cell where this word is found.

My easy way so far works:
With 'application.goto' I go perfectly to a cell which I know it contains that word...but if I insert a row (or more), my cursur moves up...

So if anybody can help me in the right direction I would be very thankful!
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
This found "fish" in column B.
VBA Code:
Range("B:B").Find(What:="fish", After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False).Activate
 
Upvote 0
VBA Code:
Sub Find_AMS()
    Dim FndRng As Range, sh As Worksheet, s As String

    Set sh = ActiveSheet
    s = Application.InputBox("What to find?")

    With sh
        Set FndRng = .Cells.Find(s, LookIn:=xlValues)
        If Not FndRng Is Nothing Then
            FndRng.Select
        Else
            MsgBox s & " is not found!"
        End If
    End With
End Sub
 
Upvote 0
Thanks a lot for the swift reply to both!

Dave's VBA works perfectly but I have already a pushbutton called 'AMS' so the inputBox should be removed...
Trying to adjust it now.
 
Upvote 0

Forum statistics

Threads
1,214,590
Messages
6,120,423
Members
448,961
Latest member
nzskater

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