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

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

pbornemeier

Well-known Member
Joined
May 24, 2005
Messages
3,896
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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,151,824
Messages
5,766,657
Members
425,367
Latest member
Boboka

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
Top