Poppenhoffer
Poppenhoffer

Reputation: 39

How to remove formula from cell and replace with number in VBA?

Say I've got a cell, C1. The formula in C1 is =A1*B1, which equals 2. How do I remove the formula and replace it with just the resulting number after it's been calculated? I've tried this:

Dim x As Long

x = .Range("C1").Value
.Range("C1").Value = x

This does not work, because x attempts to store the formula, not the calculation of said formula.

Upvotes: 0

Views: 104

Answers (1)

Tom
Tom

Reputation: 9878

If you want the result of the calculation just use

With .Range("C1")
    .Value2 = .Value2
End With

If you want the formula use .Formula

Upvotes: 1

Related Questions