Converting Text Array Search from Cell to VBA Code

goughar

New Member
Joined
Dec 5, 2005
Messages
16
I've searched and can't find how to do what I'm looking for. I've posted a sample table below with the excel formula that gets what I need, and the VBA code I'm trying to use. Essentially, I need to use instr to search for Word1 OR Word2. Thanks for the help!
Excel Workbook
BCD
2TypeDescription
3356909dogcatmouseelephantyep
4V49504mouse
51009383catdog
68403-2elephantcat
73xjuh45dogdeeryep
8203029fox
Sheet1
Excel 2003
Cell Formulas
RangeFormula
D3=IF(AND(LEFT(B3,1)="3",COUNT(SEARCH({"cat","deer"},C3))),"yep","")
D4=IF(AND(LEFT(B4,1)="3",COUNT(SEARCH({"cat","deer"},C4))),"yep","")
D5=IF(AND(LEFT(B5,1)="3",COUNT(SEARCH({"cat","deer"},C5))),"yep","")
D6=IF(AND(LEFT(B6,1)="3",COUNT(SEARCH({"cat","deer"},C6))),"yep","")
D7=IF(AND(LEFT(B7,1)="3",COUNT(SEARCH({"cat","deer"},C7))),"yep","")
D8=IF(AND(LEFT(B8,1)="3",COUNT(SEARCH({"cat","deer"},C8))),"yep","")


Code:
Option Compare Text

Sub Animal()

Do
    If Left(ActiveCell.Offset(0, -2), 1) = "3" And InStr(ActiveCell.Offset(0, -1), "cat") Then 'need to add an array with "cat" and "deer"...
    
        ActiveCell.Value = "Yep"
        ActiveCell.Offset(1, 0).Select
    
    Else
    
        ActiveCell.Offset(1, 0).Select
  
    End If
   
Loop Until IsEmpty(ActiveCell.Offset(0, -2))



End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Try

Code:
If Left(ActiveCell.Offset(0, -2), 1) = "3" And (InStr(ActiveCell.Offset(0, -1), "cat") > 0 Or InStr(ActiveCell.Offset(0, -1), "deer") > 0) Then
 
Upvote 0
Thanks for the help!

I tried your suggestion, but get the Object required error. I tried playing with it, but couldn't figure out why it won't work...

I also tried this and it did not work....
Code:
If Left(ActiveCell.Offset(0, -2), 1) = "3" And InStr(ActiveCell.Offset(0, -1), Array("cat", "deer"), 0) Then
 
Upvote 0
Opps, I replied before seeing your 2nd suggestion. That one works exactly as I need.

Many thanks!
 
Upvote 0
Sorry for the confusion. I deleted my original suggestion when I realised it wouldn't work.
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

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