Hello csch123,
Here is an update version of the macro. If any phrase you mentioned above is found in column "U", it will be changed to the replacement phrase.
' Thread: http://www.excelforum.com/excel-programming/838317-macro-help-needed.html
' Poster: csch12
' Written: June 14, 2012
' Updated: June 18, 2012
' Author: Leith Ross (www.excelforum.com)
Sub Macro1B()
Dim AddressData As Variant
Dim AddxWks As Worksheet
Dim GroupRng As Range
Dim HelpGroupRng As Range
Dim HelpWks As Worksheet
Dim i As Integer
Dim InvoiceRng As Range
Dim Phrase As Variant
Dim Phrases(1 To 6, 1 To 2) As Variant
Dim RngEnd As Range
Dim RowCnt As Long
Dim ServiceRng As Range
Dim Text As String
Set HelpWks = Worksheets("Milestone Help")
Set AddxWks = Worksheets("Address Values")
Set InvoiceRng = Names("Invoices").RefersToRange
Set GroupRng = Names("Group").RefersToRange
Set HelpGroupRng = HelpWks.Range("E2")
Set RngEnd = HelpWks.Cells(Rows.Count, InvoiceRng.Column).End(xlUp)
If RngEnd.Row < InvoiceRng.Row Then Exit Sub
Set InvoiceRng = InvoiceRng.Resize(RowSize:=RngEnd.Row - InvoiceRng.Row + 1)
Set GroupRng = GroupRng.Resize(RowSize:=InvoiceRng.Rows.Count)
' Search for these phrases -----> Replace with these phrases
Phrases(1, 1) = "*Case*Evaluation*": Phrases(1, 2) = "Case Eval Complete"
Phrases(2, 1) = "*Eligibility*": Phrases(2, 2) = "Eligibilty Eval Complete"
Phrases(3, 1) = "*Off-Treatment*": Phrases(3, 2) = "Off-Treatment Form"
Phrases(4, 1) = "*Follow-up 1*": Phrases(4, 2) = "Follow-up 1"
Phrases(5, 1) = "*Follow-up 2*": Phrases(5, 2) = "Follow-up 2"
Phrases(6, 1) = "*Follow-up 3*": Phrases(6, 2) = "Follow-up 3"
' Set Column "W" to US currency format.
HelpWks.Range("W1").EntireColumn.NumberFormat = "$#,##0.00"
For Each Cell In HelpGroupRng.Resize(RowSize:=InvoiceRng.Rows.Count)
FoundIt = Application.Match(Cell, GroupRng, 0)
' Copy the Address data if the Group and Invoice exist.
If VarType(FoundIt) <> vbError And Cell.Offset(0, -4) <> "" Then
AddressData = GroupRng.Rows(FoundIt).Offset(0, 1).Resize(1, 7).Value
Cell.Offset(0, 4).Resize(1, 7).Value = AddressData
End If
' Service Performed is in Column "U".
Set ServiceRng = Cell.Offset(0, 16)
' Check if Service Performed requires any changes.
Text = ServiceRng.Value
For i = 1 To UBound(Phrases)
If LCase(Text) Like LCase(Phrases(i, 1)) Then
ServiceRng.Value = Phrases(i, 2)
Exit For
End If
Next i
Next Cell
End Sub
Bookmarks