code help

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to Wrap an existing formularized Cell with the Function =VALUE()
using a VBA Statement. The below is not quite working . Can someone assist
me in getting the proper syntax to get it going???

Tks in Advance..
Jim May


Sub Macro5()
'
' Macro5 Macro
' Macro recorded 6/29/2006 by Jim May
'Step 1:
ActiveCell.Formula =
Application.WorksheetFunction.Substitute(ActiveCell.Formula, "=", "$")
'Step 2:
ActiveCell.Formula =
Application.WorksheetFunction.Substitute(ActiveCell.Formula, "$", "=VALUE(""
&")

End Sub
 
How about:

with activecell
if .hasformula then
.formula = "=value(" & mid(.formula, 2) & ")"
end if
end with

I'd be very careful using the $ signs. Absolute range addresses could be
severely messed up.
 
you need a closing ")" on the "=value(" statement
so something like

Application.WorksheetFunction.Substitute(ActiveCell.Formula, "$", "=VALUE("
& ActiveCell.Formula & ")")

should do it.n Post back if that does not work.

Please rate this post if it's helpful to you.
 
John Thanks,
Still getting R/T 1004 with:

ActiveCell.Formula =
Application.WorksheetFunction.Substitute(ActiveCell.Formula, "=", "$")
ActiveCell.Formula =
Application.WorksheetFunction.Substitute(ActiveCell.Formula, "$", "=VALUE(" &
ActiveCell.Formula & ")")

Thanks for your help, we're almost there, I can taste it...
 
This will replace any $ in your formula as well, so I think it should be

ActiveCell.Formula = _
Application.Substitute(ActiveCell.Formula, "=", "~~")
ActiveCell.Formula = _
Application.Substitute(ActiveCell.Formula, "~~", "=VALUE(") & ")"

but what is wrong with Dave's suggestion?
--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
Bob,
Thanks - it (your code) works great;
and as far as Dave's code... - I had not seen it until AFTERWARDS.
It too is worthy!!
Appreciation here,,
Jim May
 
It is better IMO <vbg>

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top