finding words within other words with an Excel macro

5 pts.
Tags:
Excel 2007
Excel macros
Microsoft Excel
column B has 2 letter words, the next 3 then 4 and so forth. I am looking to find the words in each column to the right to find all of theentrie that contain it and change the color of only the 2 or 3 or 4... letters in the new word for all words in each of the colomns to the right. Example: AA would find AAH, AAL, BAA, BAAL, BAASKAAP, ETC. 78 words total. the 2 letter words in column B could make the letters BLUE in the other columns and the 3 letter words GREEN in the other column and a different color for each column. Therre are 14 columns of words with 300,000 word combinations. I am looking for those smaller words within the larger words.
ASKED: September 19, 2008  5:59 PM
UPDATED: September 20, 2008  9:26 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

It took me a few minutes but this Excel macro should do the trick for you. Bascially it’s going to go row by row, for all the columns and see if the values exist in any of the values in the columns to the right. Each source column should get a different column.

<pre> Dim i As Integer, j As Integer, Word As String, Col As Integer, SourceCol As Integer
i = 1
SourceCol = 65
Do Until Range(Chr(SourceCol) & 1).Value = “”
i = 1
Do Until Range(Chr(SourceCol) & i).Value = “”
Word = Range(Chr(SourceCol) & i).Value
j = 1
Col = 66
Do Until Range(Chr(Col) & j).Value = “”
j = 1
Do Until Range(Chr(Col) & j).Value = “”
Range(Chr(Col) & j).Select
If InStr(Range(Chr(Col) & j).Value, Word) <> 0 Then
Range(Chr(Col) & j).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ColorIndex = SourceCol – 60
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End If
j = j + 1
Loop
Col = Col + 1
j = 1
Loop
i = i + 1
Loop
SourceCol = SourceCol + 1
Loop</pre>

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following