Replace in a formula

vabulden

New Member
Joined
Apr 8, 2013
Messages
5
Hello! I'm looking for a macro that can look in a formula for a specific text and change it.
Example:
I have a formula "=DATE(2013,2,1)" which is part of a complex formula
I need to change it to "=DATE(YEAR(A$1);MONTH(A$1);1)"
When I record the macros I receive:
Code:
Cells.Replace What:="2013,2", Replacement:="year(a$1);month(a$1)", LookAt _
        :=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False

But when i run the code it doesn't work.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hello! I'm looking for a macro that can look in a formula for a specific text and change it.
Example:
I have a formula "[highlight]=DATE(2013,2,1)[/highlight]" which is part of a complex formula
I need to change it to "[highlight]=DATE(YEAR(A$1);MONTH(A$1);1)[/highlight]"
When I record the macros I receive:
Code:
Cells.Replace What:="2013,2", Replacement:="year(a$1);month(a$1)", LookAt _
        :=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False

But when i run the code it doesn't work.
Welcome to the MrExcel board!

In the one part you have commas as separators but in the other part you have semicolons.
One of those formats will be invalid on your system and I think that is the issue.
 
Upvote 0
VBA uses comma instead of semicolon also in my italian version
Code:
Cells.Replace What:="(2013,2", Replacement:="(year(k$3),month(k$3)", LookAt _
        :=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
 
Upvote 0

Forum statistics

Threads
1,206,921
Messages
6,075,584
Members
446,147
Latest member
homedecortips

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