Modifying the search code

golf401

New Member
Joined
May 4, 2003
Messages
40
I have a search macro that works quite well. (search code was found on this site, i do not take credit for writing this, i did modify it slightly) But i wanted to modify it so it only searches in column A (which contains text/numbers.. p90834.pdf) and if found....... it gets highlighted......which works. But in column B ..... next to the cell I would like it to write .... Yes. The reason for this is because column B is the result column..... was it found? Here is the code.....

Code:
Sub Test()
    Dim What As String
    Dim Found As Range
    Dim firstAddress As String
    Dim Response
    What = InputBox("Search for :")
    If What = "" Then Exit Sub
        Set Found = Cells.Find(What)
        If Not Found Is Nothing Then
            firstAddress = Found.Address
            Do
                Found.Activate
                Response = MsgBox("Highlight?", vbYesNo + vbQuestion)
                If Response = vbNo Then Exit Sub
                    If Response = vbYes Then
                        ActiveCell.Interior.Color = vbYellow
                        
                    End If
                Set Found = Cells.FindNext(After:=ActiveCell)
                If Found.Address = firstAddress Then Exit Do
            Loop
        End If
    MsgBox "Search Ended!"
End Sub

Private Sub CommandButton1_Click()
Call Test
End Sub
thanks in advance

golf401
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
hi!
try this!

Sub Test()
Dim What As String
Dim Found As Range
Dim firstAddress As String
Dim Response
What = InputBox("Search for :")
If What = "" Then Exit Sub
Set Found = Cells.Find(What)
If Not Found Is Nothing Then
firstAddress = Found.Address
Do
Found.Activate
found.offset(0,1).value="yes"
Response = MsgBox("Highlight?", vbYesNo + vbQuestion)
If Response = vbNo Then Exit Sub
If Response = vbYes Then
ActiveCell.Interior.Color = vbYellow


End If
Set Found = Cells.FindNext(After:=ActiveCell)
If Found.Address = firstAddress Then Exit Do
Loop
End If
MsgBox "Search Ended!"
End Sub

Private Sub CommandButton1_Click()
Call Test
End Sub
 
Upvote 0
cool.......that worked! Now all i need to figure out is....... how to only search column a only!
 
Upvote 0
hi!
ok. try this.


Sub Test()
Dim What As String
Dim Found As Range
Dim firstAddress As String
Dim Response
Columns("A:A").Select
What = InputBox("Search for :")
If What = "" Then Exit Sub
Set Found = Selection.Find(What)
If Not Found Is Nothing Then
firstAddress = Found.Address
Do
Found.Activate
found.offset(0,1).value="yes"
Response = MsgBox("Highlight?", vbYesNo + vbQuestion)
If Response = vbNo Then Exit Sub
If Response = vbYes Then
ActiveCell.Interior.Color = vbYellow


End If
Set Found = Selection.FindNext(After:=ActiveCell)
If Found.Address = firstAddress Then Exit Do
Loop
End If
MsgBox "Search Ended!"
End Sub

Private Sub CommandButton1_Click()
Call Test
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,216
Messages
6,123,669
Members
449,114
Latest member
aides

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