Search cells C and D for partial match in each row.

nvdp2002

New Member
Joined
Nov 10, 2015
Messages
5
Hi All,

Firstly thank you to all of you who have been helping each other. The posts here have gotten me through tones of work.

I need a little help with a search and copy macro. Im usually ok with this kind of thing but the problem is i cant find a way to search 2 adjacent cells for a partial match.
I can use the Instr function on a single cell down through all the rows but i cant get it to check both cells. In my case its C and D.

ABBCB
ABABA
BCBAA

<tbody>
</tbody>

In the second and third column i need the adjacent cells to be checked for "C" for example.
After C is found i will copy the row to another sheet in the same workbook.

Thank you very much for your help.

Nasser
 

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
Try something like this...

Code:
    [COLOR=darkblue]For[/COLOR] [COLOR=darkblue]Each[/COLOR] cell [COLOR=darkblue]In[/COLOR] Range("C2", Range("C" & Rows.cont).End(xlUp))
        [COLOR=darkblue]If[/COLOR] InStr(1, cell.Value, "C", 1) And InStr(1, cell.Offset(, 1).Value, "C", 1) [COLOR=darkblue]Then[/COLOR]
           cell.EntireRow.Copy
           [COLOR=green]'Paste it somewhere[/COLOR]
        [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
    [COLOR=darkblue]Next[/COLOR]


Or use the Autofilter method.

Code:
    [COLOR=darkblue]With[/COLOR] Range("A1", Range("D" & Rows.cont).End(xlUp))
        .AutoFilter Field:=3, Criteria1:="*C*"  [COLOR=green]'filter column C[/COLOR]
        .AutoFilter Field:=4, Criteria1:="*C*"  [COLOR=green]'filter column D[/COLOR]
        .SpecialCells(xlCellTypeVisible).EntireRow.Copy
        [COLOR=green]'Paste it somewhere[/COLOR]
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]
 
Last edited:
Upvote 0
Wow..... I should have been able to work that out. Thanks allot for the help. The offset option is exactly what i needed. You rock !
 
Upvote 0

Forum statistics

Threads
1,215,261
Messages
6,123,933
Members
449,134
Latest member
NickWBA

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