Replacing Unwanted Text

ocsicnar

New Member
Joined
Sep 16, 2015
Messages
2
I've spent a good 1/2 day searching for the topic, but it either does not exist or I am not explaining it correctly. I hope someone can help.

I have a worksheet that tracks everyone's itinerary. If he/she is on "VC" (Vacation) or "SK" (Sick), the person is required to use specific codes (there are only 7 of them).

Can someone help me with a macro to find "unwanted" text and replace it with the word "OFFICE"? For example, someones itinerary says he'll be at Cincinnati on Monday and Tampa on Tuesday. I like to replace the city names with "OFFICE". Otherwise, the accepted codes remain intact.

So far, I only found macros with specific words to replace. But, tried to modify this one:
Sub ReplaceStrings()
Dim WantItems
Dim i As Long

WantItems = Array("VC", "JD", "CC", "FH", "BR", "HOLIDAY", "COMPANY HOLIDAY") '<-- extend as needed
Application.ScreenUpdating = False
With ActiveSheet.Range("F7:O32") 'Columns("A") <-- adjust to suit your column
For i = 0 To UBound(WantItems)
.Replace What:=IsNot WantItems(i), Replacement:="OFFICE", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Next i​
End With​
Application.ScreenUpdating = True
End Sub​
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Code:
Sub test()
Dim c As Range
For Each c In Range("F7:O32")
Select Case UCase(c.Text)
    Case "VC", "JD", "CC", "FH", "BR", "HOLIDAY", "COMPANY HOLIDAY", ""
    Case Else
         c = "OFFICE"
End Select
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,099
Messages
6,170,109
Members
452,302
Latest member
TaMere

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