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

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

SIXTH SENSE

Well-known Member
Joined
Oct 29, 2003
Messages
1,883
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
 

golf401

New Member
Joined
May 4, 2003
Messages
40
cool.......that worked! Now all i need to figure out is....... how to only search column a only!
 

SIXTH SENSE

Well-known Member
Joined
Oct 29, 2003
Messages
1,883
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
 

Watch MrExcel Video

Forum statistics

Threads
1,129,552
Messages
5,636,969
Members
416,953
Latest member
broexc

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
Top