Find Name and then activate Cell

Jaye7

Well-known Member
Joined
Jul 7, 2010
Messages
1,066
I have the following code which finds the names that I type in and returns the cells address and then loops in case the name is found again, can someone please help to modify the script so that if it only finds one occurrence then it goes to that cell and activates the cell, otherwise if it finds the name again then it gives me the option to go to the next found cell and activate the cell, but if I selected no to going to the second found name then the first found name would still have the cell ativated.

I hope I haven't confused you too much.

code:
Sub Find_Value_And_Goto()
Dim strFind As String
Dim rFound As Range
Dim lLoop As Long
Dim lReply As Long
Dim bFound As Boolean
strFind = InputBox("Please enter the NAME you wish to search for:", "Search for NAME in this file")

If strFind = vbNullString Then Exit Sub


With ActiveSheet.Range(Cells(2, 1), Cells(100, 1))
Set rFound = .Cells(1, 1)
For lLoop = 1 To WorksheetFunction.CountIf(.Cells, "*" & strFind & "*")
bFound = True
If lLoop > 1 Then MsgBox "Found another occurrence"
Set rFound = .Cells.Find(strFind, rFound, xlValues, xlPart, , , False)
lReply = MsgBox(strFind & " is in cell " & rFound.Address & " Go there?", vbOKOnly + vbQuestion)
If lReply = vbOK Then Application.Goto rFound, True
ActiveCell.Name = "NAME"
Next lLoop
End With

If bFound = False Then MsgBox "Cannot find " & strFind
End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,223,264
Messages
6,171,081
Members
452,377
Latest member
bradfordsam

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