Forum

A Macro Change and ...
 
Notifications
Clear all

A Macro Change and replace an Excel Formula

9 Posts
2 Users
0 Reactions
238 Views
(@david_ng)
Posts: 310
Reputable Member
Topic starter
 

How to modify following  script to suit change the

 

Sub replace()
 What = InputBox("Word to search")
 repl = InputBox("Word to replace")
 Sheets().Select

 Selection.replace What:=What, Replacement:=repl, LookAt:=xlPart, _
 SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
 ReplaceFormat:=False
  End Sub

My Request : I want to change and replace

e.g.In cell A1

=B5*6        changed to =B5*4

In cell A2

=B6*6       changed to =B6*4

and so on  ie operator change from *6    to *4    etc etc  

but seems can not use Find and Replace function for formula change to attan the desired result 

 
Posted : 16/05/2019 3:51 am
(@debaser)
Posts: 836
Member Moderator
 

You'll need to handle the * wildcard by replacing it with ~* like this:

 

Sub replaceText()

What = replace(InputBox("Word to search"), "*", "~*")

repl = InputBox("Word to replace")

Sheets().Select

Selection.replace What:=What, Replacement:=repl, LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ ReplaceFormat:=False

End Sub

 
Posted : 16/05/2019 10:32 am
(@david_ng)
Posts: 310
Reputable Member
Topic starter
 

Thanks Velourla , will have a go on that...

 
Posted : 16/05/2019 8:02 pm
(@david_ng)
Posts: 310
Reputable Member
Topic starter
 

Tied but the macro doesn't work pls refer attached sample.

 
Posted : 16/05/2019 8:17 pm
(@david_ng)
Posts: 310
Reputable Member
Topic starter
 

Kindly review the Macro module  per attach to see if any things goes wrong,  now doesn't work at all..

 
Posted : 17/05/2019 2:22 am
(@debaser)
Posts: 836
Member Moderator
 

That's your original code, not mine. Also, as written it only works on whatever cells you have selected when you run it - was that your intention?

 
Posted : 17/05/2019 6:30 am
(@david_ng)
Posts: 310
Reputable Member
Topic starter
 

Thanks, understand.  Macro work  on selected cells.

I need to modiy if work on others cells.

 
Posted : 17/05/2019 10:21 pm
(@debaser)
Posts: 836
Member Moderator
 

Which cells specifically?

 
Posted : 18/05/2019 9:33 am
(@david_ng)
Posts: 310
Reputable Member
Topic starter
 

Cells at random in each worksheet.

Anyway I master the tips you so kind share, Velouria, and the small VB tools should work fine..

 
Posted : 23/05/2019 4:37 am
Share: