简体   繁体   中英

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.

If you want the result of the calculation just use

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

If you want the formula use .Formula

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM