Re: June/July 2008 Challenge of the Month
Here is my (very long) VBA solution...sorry I am still pretty new to VBA (trying to teach myself):
I will say, that I enjoyed trying to figure this out.
Here is my (very long) VBA solution...sorry I am still pretty new to VBA (trying to teach myself):
Code:
Sub finding()
Dim rFound As Range
counter = 1
'Determine how many Phrases there are in the range
textcountp = WorksheetFunction.CountA(Range("a:a")) - 1
'Determine how many Keywords there are in the range
textcountK = WorksheetFunction.CountA(Range("d:d")) - 1
With Application.FindFormat.Font
.Subscript = False
.ColorIndex = xlAutomatic
End With
'Loops until you have gone through all of the keywords
Do Until counter2 = textcountK
'Loops until you have gone through all of the phrases
Do Until counter = textcountp + 1
On Error Resume Next
Range("a2:a" & textcountp + 1).Select
With Sheet1
'Finds the keyword
Set rFound = Range("a2:a" & textcountp + 1).Find(What:=Cells(2 + counter3, 4), After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=True).Activate
If counter > 1 Then
'Finds the keyword again
Do Until again = counter
Selection.FindNext(After:=ActiveCell).Activate
If again = 0 Then
again = again + 2
Else
again = again + 1
End If
Loop
End If
counter = counter + 1
ActiveCell.Offset(0, 1).Select
'Copies the keyword if the cell is empty
If ActiveCell.Value = Empty Then
Cells(2 + counter3, 5).Copy
ActiveSheet.Paste
End If
If again = 0 Then
Else
again = 1
End If
On Error GoTo 0
If Not rFound Is Nothing Then Application.Goto rFound, True
End With
Loop
counter2 = counter2 + 1
counter3 = counter3 + 1
counter = 1
Loop
End Sub
I will say, that I enjoyed trying to figure this out.