View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default How can I replace a formula with its result using a macro?

Hi David,

Hi Norman,
Does that work for you without a loop.
It did not work for me.


Given that *you* query it, my response is affirmative, but tinged with a
tentativeness that I would not normally expect:

Sub Demo()
Dim rng As Range
Dim myValue1 As Double
Dim myValue2 As Double

Set rng = ActiveSheet.Range("A20:K20")

'Insert formula into each cell
rng.FormulaR1C1 = "=COLUMN()"

'Just not to have the same formula throughout
rng(1) = "=Pi()"

'Print a control value
Debug.Print Application.Sum(rng), "Formulas Total"

' Convert Formulas to values
With rng
.Value = .Value
End With

'Print Values total
Debug.Print Application.Sum(rng), "Values Total"

End Sub

I would have expected to need to loop only if the range comprised multiple
areas.


What am I missing?

---
Regards,
Norman



"David McRitchie" wrote in message
...
Hi Norman,
Does that work for you without a loop.
It did not work for me.

There was code posted in this group today by another David
that works on a selection and without a loop.
http://google.com/groups?threadm=FA9...0microsoft.com

Can't give much more credit than that since a full name was not provided.