View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Bernie Deitrick Bernie Deitrick is offline
external usenet poster
 
Posts: 5,441
Default Simple macro, even simpler programmer!

DA,

Try it like this: I've assumed you have named ranges CalculatedCost and
HardCodedCostValue.

Sub Iterate_On_Cost()

Dim Difference As Double

Difference = 1
While Difference 0.001
Range("HardCodedCostValue").Value = _
Range("CalculatedCost").Value
Application.Calculate
Difference = Abs(Range("CalculatedCost").Value - _
Range("HardCodedCostValue").Value)
Wend

End Sub


HTH,
Bernie
MS Excel MVP


"DA" wrote in message
...
I'm trying to paste the value of one calculated cell onto another that
just has a vlaue unitl they are essentially the same. The macro below
seems to only iterate once, whereas it usually take three or fout
iterations to get them close. So, clearly something is wrong. Please
help.

Thanks
Dean

Sub Iterate_On_Cost()

Dim Difference As Variant
Dim CalculatedCost As Variant
Dim HardCodedCostValue As Variant


Do
Range("CalculatedCost").Select
Selection.Copy
Range("HardCodedCostValue").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Difference = Abs(CalculatedCost - HardCodedCostValue)
Loop Until Difference < 0.001

End Sub