Macro to find and replace formulas with cell value

lx_lthr2000

New Member
Joined
Apr 16, 2014
Messages
7
Hi All

Apologies if this has already been asked in the forum, but I couldn't find it from my search.

I'm looking for a macro that will find all the formulas in a workbook (with multiple tabs) that specifically begin with "=HsGetValue" and replace it with the value of that cell - e.g. if a cell has the formula =HSGetValue(......) which gives the value 4, then I want to replace the formula / cell with that value (i.e. a bit like 'past special, value only').

Hope that makes sense. Would be grateful for any help.

Many thanks
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
I'll test this right now, but try it (on a copy) meanwhile:


Code:
sub specformula2val()
dim x as integer
for x = 1 to sheets.count
for each cell in sheets(x).usedrange
if left(cell.formula,11) = "=HSGetValue" then
cell.value = cell.value
end if
next cell
next x
end sub
 
Last edited:
Upvote 0
Many thanks for the quick response. Have just tried it and unfortunately it does not seem to do anything....

I'll test this right now, but try it (on a copy) meanwhile:


Code:
sub specformula2val()
dim x as integer
for x = 1 to sheets.count
for each cell in sheets(x).usedrange
if left(cell.formula,11) = "=HSGetValue" then
cell.value = cell.value
end if
next cell
next x
end sub
 
Upvote 0
Is the formula =HSGETVALUE ? The if statement and/or left function seems to be case sensitive.
 
Last edited:
Upvote 0
Hi

Many apologies for the delayed response, but I was off work due to a personal bereavement.

However, I just wanted to say thank you very much, as having adjusted for the point below, the macro now works perfectly.

My only follow on point if I may is how would I get the macro to not just pick up "=HsGetValue" but also "=-HsGetValue" or "=(HsGetValue"

Is the formula =HSGETVALUE ? The if statement and/or left function seems to be case sensitive.
 
Upvote 0
Try:

if left(cell.formula,11) = "=HsGetValue" or left(cell.formula,12) = "=-HsGetValue" or left(cell.formula,12) = "=(HSGetValue" then
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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