Using an if-then statement to search for individual characters in a column of cells

DLAhr

New Member
Joined
Jan 28, 2014
Messages
4
[TABLE="width: 689"]
<tbody>[TR]
[TD]GLYT[/TD]
[TD]Genlyte Group Inc.[/TD]
[TD]4◄[/TD]
[TD]4◄[/TD]
[TD="align: right"]2/4/2005[/TD]
[TD="align: right"]$86.98[/TD]
[TD="align: right"]$90.04[/TD]
[TD="align: right"]2/11/2005[/TD]
[TD="align: right"]3.52%[/TD]
[/TR]
[TR]
[TD]SGTL[/TD]
[TD]Sigmatel, Inc.[/TD]
[TD]€◄[/TD]
[TD]€[/TD]
[TD="align: right"]1/14/2005[/TD]
[TD="align: right"]$36.40[/TD]
[TD="align: right"]$40.01[/TD]
[TD="align: right"]2/11/2005[/TD]
[TD="align: right"]9.92%[/TD]
[/TR]
[TR]
[TD]LDIS[/TD]
[TD]Leadis Technology, Inc.[/TD]
[TD]∩⌂[/TD]
[TD]⌂[/TD]
[TD="align: right"]1/14/2005[/TD]
[TD="align: right"]$7.52[/TD]
[TD="align: right"]$6.81[/TD]
[TD="align: right"]2/11/2005[/TD]
[TD="align: right"]-9.39%[/TD]
[/TR]
[TR]
[TD]CEDC[/TD]
[TD]Central European Distr[/TD]
[TD]AC[/TD]
[TD]AC[/TD]
[TD="align: right"]1/28/2005[/TD]
[TD="align: right"]$32.37[/TD]
[TD="align: right"]$33.85[/TD]
[TD="align: right"]2/11/2005[/TD]
[TD="align: right"]4.57%[/TD]
[/TR]
[TR]
[TD]SWFT[/TD]
[TD]Swift Transportation [/TD]
[TD]ACHS©[/TD]
[TD]ACH©[/TD]
[TD="align: right"]1/7/2005[/TD]
[TD="align: right"]$33.53[/TD]
[TD="align: right"]$42.59[/TD]
[TD="align: right"]2/11/2005[/TD]
[TD="align: right"]27.02%[/TD]
[/TR]
[TR]
[TD]HUBG[/TD]
[TD]Hub Group, Inc.[/TD]
[TD]GQ[/TD]
[TD]GNQ[/TD]
[TD="align: right"]1/7/2005[/TD]
[TD="align: right"]$31.87[/TD]
[TD="align: right"]$32.33[/TD]
[TD="align: right"]3/22/2005[/TD]
[TD="align: right"]-45.66%[/TD]
[/TR]
[TR]
[TD]WRLD[/TD]
[TD]World Acceptance Co[/TD]
[TD]ABCGX7[/TD]
[TD]ABCG7[/TD]
[TD="align: right"]1/7/2005[/TD]
[TD="align: right"]$35.43[/TD]
[TD="align: right"]$35.28[/TD]
[TD="align: right"]3/22/2005[/TD]
[TD="align: right"]-30.10%[/TD]
[/TR]
[TR]
[TD]RSTI[/TD]
[TD]Rofin-Sinar Tech[/TD]
[TD]GQ[/TD]
[TD]G[/TD]
[TD="align: right"]1/7/2005[/TD]
[TD="align: right"]$67.56[/TD]
[TD="align: right"]$65.81[/TD]
[TD="align: right"]3/22/2005[/TD]
[TD="align: right"]-25.01%[/TD]
[/TR]
[TR]
[TD]SPF[/TD]
[TD]Standard Pacific Corp.[/TD]
[TD]RSX7[/TD]
[TD]7[/TD]
[TD="align: right"]1/7/2005[/TD]
[TD="align: right"]$14.41[/TD]
[TD="align: right"]$12.53[/TD]
[TD="align: right"]3/22/2005[/TD]
[TD="align: right"]-33.56%[/TD]
[/TR]
[TR]
[TD]CIG[/TD]
[TD]Companhia Energetica [/TD]
[TD]Y2[/TD]
[TD]JY[/TD]
[TD="align: right"]1/11/2013[/TD]
[TD="align: right"]$9.62[/TD]
[TD="align: right"]$8.00[/TD]
[TD="align: right"]1/3/2014[/TD]
[TD="align: right"]-16.87%[/TD]
[/TR]
[TR]
[TD]ALV[/TD]
[TD]Autoliv Inc.[/TD]
[TD]DM2[/TD]
[TD]2[/TD]
[TD="align: right"]6/28/2013[/TD]
[TD="align: right"]$77.39[/TD]
[TD="align: right"]$89.73[/TD]
[TD="align: right"]1/3/2014[/TD]
[TD="align: right"]15.95%[/TD]
[/TR]
[TR]
[TD]CRRC[/TD]
[TD]Courier Corporation[/TD]
[TD]O¿[/TD]
[TD]¿[/TD]
[TD="align: right"]11/29/2013[/TD]
[TD="align: right"]$18.72[/TD]
[TD="align: right"]$17.81[/TD]
[TD="align: right"]1/3/2014[/TD]
[TD="align: right"]-4.86%[/TD]
[/TR]
[TR]
[TD]SMCI[/TD]
[TD]Super Micro Computer[/TD]
[TD]O«[/TD]
[TD]O«[/TD]
[TD="align: right"]12/6/2013[/TD]
[TD="align: right"]$16.92[/TD]
[TD="align: right"]$16.71[/TD]
[TD="align: right"]1/3/2014[/TD]
[TD="align: right"]-1.24%[/TD]
[/TR]
[TR]
[TD]AHL[/TD]
[TD]Aspen Insurance Hold[/TD]
[TD]DEM[/TD]
[TD]D[/TD]
[TD="align: right"]12/6/2013[/TD]
[TD="align: right"]$40.83[/TD]
[TD="align: right"]$40.54[/TD]
[TD="align: right"]1/3/2014[/TD]
[TD="align: right"]-0.71%[/TD]
[/TR]
[TR]
[TD]TEX[/TD]
[TD]Terex Corporation[/TD]
[TD]¥€«[/TD]
[TD]¥€«[/TD]
[TD="align: right"]12/27/2013[/TD]
[TD="align: right"]$41.63[/TD]
[TD="align: right"]$41.28[/TD]
[TD="align: right"]1/3/2014[/TD]
[TD="align: right"]-0.84%[/TD]
[/TR]
[TR]
[TD]CBPO[/TD]
[TD]China Biologic Products [/TD]
[TD]JU[/TD]
[TD]S[/TD]
[TD="align: right"]5/24/2013[/TD]
[TD="align: right"]$26.52[/TD]
[TD="align: right"]$28.11[/TD]
[TD="align: right"]1/3/2014[/TD]
[TD="align: right"]6.00%[/TD]
[/TR]
[TR]
[TD]SNTS[/TD]
[TD]Santarus, Inc.[/TD]
[TD]€◄[/TD]
[TD]HL€[/TD]
[TD="align: right"]7/12/2013[/TD]
[TD="align: right"]$25.57[/TD]
[TD="align: right"]$31.96[/TD]
[TD="align: right"]1/3/2014[/TD]
[TD="align: right"]24.99%[/TD]
[/TR]
</tbody>[/TABLE]

Range("C3").Select
For combo = 0 To counter

If ActiveCell.Offset(combo, 0).Value = "MQ" Then
Range(ActiveCell.Offset(combo, -2), ActiveCell.Offset(combo, 6)).Select
Selection.Copy

In the "If-Then" statement, I would like to be able to pick out any combination of 2 characters in the sample data set - not just "MQ" which I used as an illustration. For example, I might want to choose the combination "D" & "M", or "A" & "C", or any other combination of two characters.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
I found my own simple answer by using the LIKE operator instead of = in the IF statement above which allows me to use wildcard characters. So a new working statement is --> If ActiveCell.Offset(combo, 0).Value Like "D*M" Then
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

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