VBA to change formula in worksheets

sandaflo

New Member
Joined
Jan 29, 2010
Messages
7
Hello,

relative newbie to VBA, but I would imagine the following can be done. I have a workbook with a couple hundred worksheets, all identical in layout (templates for audit functions). witin the tabs are formulas that assign a value to a data validation dropdown value, provding an audit score.
Formula reads as

=IF(H23="SAT",100,IF(H23="N/A",100,IF(H23="UNSAT",50,IF(H23="REC",70,IF(H23="SELECT",0)))))

I would like to change the "SAT" and "N/A" values from 100 to a different value (i.e. 95), thus changing the total score.

Is there a way to loop through the workbook and find/replace the formula or change a portion of the formula? Can VBA treat a formula like a test string?

thank you
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Using FIND/REPLACE (Ctrl + H), you can look for ",100," and change it to ",95," (don't use quotes ""). Ensure that in the "Within" option you select Workbook.

Ron
 
Upvote 0
Hi Ron2K

I think above Find/replace wont work,

What i understand is that Sandalfo wants to make changes in the formula and not in the data.. if i guess it correct the above find replace will make changes in data and not in formula..
 
Upvote 0
Hi Ron2K

I think above Find/replace wont work,

What i understand is that Sandalfo wants to make changes in the formula and not in the data.. if i guess it correct the above find replace will make changes in data and not in formula..
If there is not data that actually has ",100," (without quotes), then only the formulas will be affected. To be on the safe side he can do the same in two steps:

1. Find: "SAT",100; Replace:"SAT",95

2. Find: "N/A",100; Replace:"N/A",95
 
Upvote 0
Or you could create a table of the values and switch to VLOOKUP this way you only need to amend the table if the values for each parameter change
 
Upvote 0
Thanks, I had no idea that fnd/replace worked on formulas. One of those excel functions I need to booknmark for the future.


thanks for the quck reply; this board is full of great people and info.
 
Upvote 0
Create a table either directly in a sheet or in the defined name manager (Insert>>Name>>Define), I created a table in the name manager and called it my_table and it refers to ={"SAT",100;"N/A",100;"REC",70;"UNSAT",50;"SELECT",0}.

Then I used VLOOKUP

=VLOOKUP(H23, my_table, 2, 0)

Which will yield the same result as the OP formula of..

=IF(H23="SAT",100,IF(H23="N/A",100,IF(H23="UNSAT",50,IF(H23="REC",70,IF(H23="SELECT",0)))))

just in a more compact and efficient formula
 
Upvote 0
How about changing the formulas to point to a cell that you change from 100 to 95 or whatever value you want. The up front cost will be larger in terms of time, but you won't have to do the find/replace again.
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,672
Members
452,937
Latest member
Bhg1984

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