vba replace code not working

I have a code in Net_Rate_Sheet_1, ReplaceNet1 that replaces text values across Net Rate Sheet 1, row 2597.

The data is now       =     the cell should be text
Zone-9 ( To Hawaii )      = 9
Zone-17 ( To Alaska )      = 17
Zone-22 ( Intra-Alaska )      = 22
Zone-23 ( From Alaska )      = 23
Zone-25 ( From Alaska )      = 25
Zone-92 ( From Hawaii )      = 92
Zone-96 ( From Hawaii )  =96

No matter what I try, I can't get the correct replacements.
It will replace, but not reduce to JUST the number - ie 92, 96, etc.
Not sure what I'm doing wrong, all of the other replacements have worked easily.
Tried xPart & xWhole....not sure what else to do.
Can anyone help?
Rerate-v5.3-sample.xlsm
Euro5Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
With Zone-9, you are missing the wildcard character * and missing the replace code for zone-14 so add lines for zone-14 also,
Make the following correction and your code should run fine.

Cells.Replace What:="*Zone-9*", Replacement:="9", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

Cells.Replace What:="*Zone-14*", Replacement:="14", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

Open in new window

0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Please disregard my previous reply.

I think that the correct sequence of your replace codes should be like this.....


Cells.Replace What:="*Zone-92*", Replacement:="92", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

Cells.Replace What:="*Zone-96*", Replacement:="96", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
        
Cells.Replace What:="*Zone-9*", Replacement:="9", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

Cells.Replace What:="*Zone-14*", Replacement:="14", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

Open in new window



Does this work now?
0
Euro5Author Commented:
This is still not working for me. I am at a loss.
This is what I get...
9 ( To Hawaii )      Zone-14 ( Intra-Oahu )      17      22      23      25      92 ( From Hawaii )      96 ( From Hawaii )
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Have you tried my last suggestion?
0
Euro5Author Commented:
Ok...getting somewhere!


This is what I end up with! Except that I get (3) 9's instead of 9,92,96
9      14      17      22      23      25      9      9

        Cells.Replace What:="Zone-92 ( From Hawaii )", Replacement:="92", LookAt:=xlWhole, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        
        Cells.Replace What:="Zone-96 ( From Hawaii )", Replacement:="96", LookAt:=xlWhole, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="Zone-9 ( To Hawaii )", Replacement:="9", LookAt:=xlWhole, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="*Zone-17*", Replacement:="17", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="*Zone-22*", Replacement:="22", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="*Zone-23*", Replacement:="23", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="*Zone-25*", Replacement:="25", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="*Zone-51*", Replacement:="52", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="*Zone-54*", Replacement:="54", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False

Open in new window

0
Euro5Author Commented:
@sktneer Sorry, responded before I saw that last post.
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Remove your replace codes for zone-9, zone-92 and zone-96 and paste the codes I suggested in my last suggestion, its working perfectly fine with me.
I am getting this....

9      14      17      22      23      25      92      96
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You are still using What:="Zone-9" instead of What:="Zone-9*" and that will create problem for zone-92 and zone-96.
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
The complete code would be like this.....

Sub ReplaceNet1()


    Cells.Replace What:="FedEx Envelope", Replacement:="1", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="FedEx 1 Lb Pak", Replacement:="1", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="FedEx 2 Lbs Pak", Replacement:="2", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="100 - 150", Replacement:="100", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="151 - 299", Replacement:="151", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="300 - 499", Replacement:="300", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="500 - 999", Replacement:="500", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="1000 - 1999", Replacement:="1000", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="2000 - 9999", Replacement:="2000", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="2000 - 4999", Replacement:="2000", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="5000 - 9999", Replacement:="5000", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="100 - 154", Replacement:="100", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="155 - 199", Replacement:="155", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="200 - 299", Replacement:="200", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="300 - 399", Replacement:="300", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="400 - 499", Replacement:="400", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="500 - 699", Replacement:="500", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="700 - 999", Replacement:="700", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="1000 - 1999", Replacement:="1000", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="2000 - 9999", Replacement:="2000", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="155 - 299", Replacement:="155", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="*Zone-92*", Replacement:="92", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="*Zone-96*", Replacement:="96", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
                
        Cells.Replace What:="*Zone-9*", Replacement:="9", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="*Zone-14*", Replacement:="14", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="*Zone-17*", Replacement:="17", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="*Zone-22*", Replacement:="22", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="*Zone-23*", Replacement:="23", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="*Zone-25*", Replacement:="25", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="*Zone-92*", Replacement:="92", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False

        Cells.Replace What:="*Zone-96*", Replacement:="96", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
     
        Cells.Replace What:="*Zone-51*", Replacement:="52", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        
        Cells.Replace What:="*Zone-54*", Replacement:="54", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False

End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Euro5Author Commented:
AH PERFECT!! I can't believe you made it so simple.
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Glad it worked for you. :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.