Replacing values separated by commas

mliang87

New Member
Joined
Feb 19, 2013
Messages
7
Hello all,

Currently I have written a macro that converts values in a cell to values mapped in another tab list.

My code is:
Code:
Sub DataFormatPR()
Dim PremiumType
Set PremiumType = Sheets("PremiumType").Range("PremiumType")
  For Each cel In PremiumType.Columns(1).Cells
        MainTemp.Replace what:=cel.Value, replacement:=cel.Offset(0, 1).Value, LookAt:=xlWhole
    Next cel
End Sub
The problem is I have TypeA, TypeB in the cell and I want it to convert to the mapped values of A, B.

How do I modify it so that it will convert the cell containing : TypeA, TypeB rather than just TypeA?

Please help!
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Change xlWhole to xlPart
You should also add the code in Orange or Excel will use whatever settings were used in the Find command the previous time it was used by code or by hand.
Rich (BB code):
Sub DataFormatPR()
    Dim PremiumType As Range
    Dim cel As Range
    
    Set PremiumType = Sheets("PremiumType").Range("PremiumType")
    For Each cel In PremiumType.Columns(1).Cells
        MainTemp.Replace What:=cel.Value, Replacement:=cel.Offset(0, 1).Value, LookAt:=xlPart, _
            MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
    Next cel
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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