Find and Replace macro

  • Thread starter Thread starter Legacy 93538
  • Start date Start date
L

Legacy 93538

Guest
Hi

I need some help with a find and replace statement i am trying to create. The code below should loop through the D column (which has values similar to this "'=G4+H4+I4+J4+K4+L4+M4+N4+O4+P4+Q4+R4"), it should then look in the cell value and for each cell ref it finds, it looks that cell ref up in the M column and replaces the cell ref with the value in the corresponing row in column L.

I have been using the following code but when it runs, it doesn't replace any of the cell refs, prehaps beacuse its looking at the value as a whole but i am not sure.

Code:
For Y = 1 To Z
    FindRef = Range("M" & 1 + Z)    'First loop with substitute values
    ReplRef = Range("L" & 1 + Z)
    
    Set MyRange = PPCWBSht.Range("D:D")
        MyRange.Replace What:=FindRef, Replacement:=ReplRef, LookAt:=xlPart, SearchOrder:=xlByRows, _
                        MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Next Y

Does anyone know of an easier way of doing this?

Thank you

Jessicaseymour :) :confused:
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I found out why the code i pasted in my first post does not work.

In the first loop it goes through the D column and looks for the cell ref in M column and replaces it with a subisitute value. I have found that it finds a cell ref inside a cell ref, for example it finds G4 inside G42.

Does anyone know if there is a way to get it look at the value between the math symbols like +cell ref+ or cell ref/?

I hope that makes sense
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,728
Members
452,939
Latest member
WCrawford

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