Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to change a cell's value from its formula 1

Status
Not open for further replies.

Luis939

MIS
Feb 28, 2003
453
US
Basically I'm trying to change the value of a cell to the value calculated by its formula. So if I have cell A1 = 1 and cell A2 = 2, and if I then have cell A3 =sum("A1","A2"), I want to be able change the value of A3 so that it equals only 3, not the formula.
I tried to assign the answer to a variable and paste it to another cell, but if i deleted either A1 or A2 or both, then the cell wouldnt be 3 anymore, and I want to be able to retain that answer

ActiveCell.FormulaR1C1 = "=sum("A1","A2")"
Let i = ActiveCell.Value
Selection.Copy
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.Value = i

The new cell has value 3, but once A1 or A3 is deleted then it doesnt work. Thanks
 
Have you found the macro recorder? It's a great way to learn how to write the VBA code to do various things. The code it generated looks something like this:
Code:
Option Explicit

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 3/13/03 by Zathras
'

'
    Range("A3").Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
    Application.CutCopyMode = False
End Sub
You can usually modify the code without too much trouble to fit your specific requirements.
 
I have another problem now...I can use the pastespecial method, but for some reason it only works for copy not cut, try it, does anyone think there is any way to make it work for cut?
 
And, as the silliest contribution to this thread, I propose you use:

activecell=activecell

This nicely replaces the formula in the active cell with its value, and looks wonderfully inane.
Rob
[flowerface]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top