这是执行您要求的操作的专家。因为你说你需要知道怎么做,所以我在几行之前添加了一些评论,以完全清楚它是如何工作的。
Option Explicit
'Declare a private variant to store the range formulas
'Variable is declared as private so that it remains in scope within the module
'Variable could also be declared as static within the sub with the same results.
Private rangeFormulas As Variant
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
'Transfer the range formulas to the variant.
rangeFormulas = Range("H5:H38").Formula
Range("H5:H38").Value = Range("H4").Value
Else
'Restore the formulas from the private variant variable.
Range("H5:H38").Formula = rangeFormulas
End If
End Sub
从技术上讲,我可以使用rangeFormulas = Range("H5:H38").Value
and Range("H5:H38").Value = rangeFormulas
,但我认为如果您恢复具有相同可见结果的公式会更好。