Search method VBA

dhutirth

New Member
Joined
May 25, 2011
Messages
2
I'm new here so at the beginning hello to everyone <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p> </o:p>
I have one problem with my EXCEL application. Earlier my application was written without VBA but now I’m trying to master my VBA skills and I’m rewriting everything. I don't now how to write this in VBA code:<o:p></o:p>
<o:p> </o:p>
For example in cell A1 a have this function<o:p></o:p>
<o:p> </o:p>
If(isnumber(search(B1;C1) );"you have a cat"; if(isnumber(search(B2;C1));"you have a dog";"you have something else"))<o:p></o:p>
<o:p> </o:p>
B1 = "cat"
B2 = "dog"
C1 = "long text with a word cat (or dog)" <o:p></o:p>
<o:p> </o:p>
This function should search for at least two different words in long text. The text will always contain word "dog" or "cat". All those words are of course only examples :) <o:p></o:p>
<o:p> </o:p>
A will by appreciate for any help<o:p></o:p>
<o:p> </o:p>
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Hi

Note Sure I understood your requirements, however try this. It can be run under comand button or spread sheet event.

Code:
Dim firstsearch, secondsearch

firstsearch = Range("b2").Text ' hold text value from range B1
secondsearch = Range("b3").Text ' hold text value from range B1

For Each animal In Range("b2:B7") ' Range to be searched
    If animal = firstsearch Then ' first search
    
      animal.Offset(0, 1).Value = "You Have a Cat"
      
      ElseIf animal = secondsearch Then ' second search
        animal.Offset(0, 1).Value = "You Have a Dog"
       Else ' anything else
       
             
          animal.Offset(0, 1).Value = "You Have Something Else"
      End If
      
Next animal

regards
 
Upvote 0
Thx for reply. I already solve my problem. I used this code:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>

Code:
With Arkusz1.Cells(1, 3)
    Set Find = .Find(what:="cat")
End With
 
If Find Is Nothing Then
 
    With Arkusz1.Cells(1, 3)
        Set Find = .Find(what:="dog")
    End With
 
    If Find Is Nothing Then
        Arkusz1.Cells(1, 1) = "you have something else"
    Else
        Arkusz1.Cells(1, 1) = "you have a dog"
    End If
 
Else
Arkusz1.Cells(1, 1) = "you have a cat"
End If

But i'll also check Yours :)
 
Upvote 0

Forum statistics

Threads
1,224,607
Messages
6,179,871
Members
452,949
Latest member
Dupuhini

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