VBA requirement for searching string that begines with...

omairhe

Well-known Member
Joined
Mar 26, 2009
Messages
2,040
Office Version
  1. 2019
Platform
  1. Windows
Hey all,

In need of a simple code that will search string in Column A that begins with "BEL" . Once searched goto target.row.

Will appreciate any help.

Thank you.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Try this
Code:
With ActiveSheet.Range("A:A")
    .Find(What:="BEL*", After:=ActiveCell.EntireRow.Cells(1, 1), LookIn:=xlValues, LookAt:=xlWhole, _
        SearchDirection:=xlNext, MatchCase:=False).Activate
End With

This is case insensitive.
 
Upvote 0
How about
Code:
Sub omairhe()
   Dim Fnd As Range
   Set Fnd = Range("A:A").Find("BEL*", , , xlWhole, , , False, , False)
   If Not Fnd Is Nothing Then Application.Goto Fnd, True
End Sub
 
Upvote 0
How about
Code:
Sub omairhe()
   Dim Fnd As Range
   Set Fnd = Range("A:A").Find("BEL*", , , xlWhole, , , False, , False)
   If Not Fnd Is Nothing Then Application.Goto Fnd, True
End Sub

Yes. What might change in your code for keeping the same column reference used before triggering the code.
Right now it will select target row and column A . whereas I would like it to select target row and keep column reference as before.

Thank you for your effort..
 
Upvote 0
Thanks Mike, I noticed your code just now. I ran it and it is working gr8. Just want the column reference to be the same as it was before running the code.

Try this
Code:
With ActiveSheet.Range("A:A")
    .Find(What:="BEL*", After:=ActiveCell.EntireRow.Cells(1, 1), LookIn:=xlValues, LookAt:=xlWhole, _
        SearchDirection:=xlNext, MatchCase:=False).Activate
End With

This is case insensitive.
 
Last edited:
Upvote 0
How about
Code:
Sub omairhe()
   Dim Fnd As Range
   Set Fnd = Range("A:A").Find("BEL*", , , xlWhole, , , False, , False)
   If Not Fnd Is Nothing Then ActiveWindow.ScrollRow = Fnd.Row
End Sub
 
Upvote 0
How about
Code:
Sub omairhe()
   Dim Fnd As Range
   Set Fnd = Range("A:A").Find("BEL*", , , xlWhole, , , False, , False)
   If Not Fnd Is Nothing Then ActiveWindow.ScrollRow = Fnd.Row
End Sub
Almost. It is now keeping the column as before but not selecting the target row.

whereas I would like it to select target row and keep column reference as before
 
Last edited:
Upvote 0
Ok, how about
Code:
Sub omairhe()
   Dim Fnd As Range
   Set Fnd = Range("A:A").Find("BEL*", , , xlWhole, , , False, , False)
   If Not Fnd Is Nothing Then Cells(Fnd.Row, ActiveCell.column).Activate
End Sub
 
Upvote 0
Ok, how about
Code:
Sub omairhe()
   Dim Fnd As Range
   Set Fnd = Range("A:A").Find("BEL*", , , xlWhole, , , False, , False)
   If Not Fnd Is Nothing Then Cells(Fnd.Row, ActiveCell.column).Activate
End Sub

Awesome. Thanks a lot.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,110
Messages
6,123,139
Members
449,098
Latest member
Doanvanhieu

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