Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
(Excel VBA)如何从变量变化的瞬间保持单元格值_Excel_Vba - Fatal编程技术网

(Excel VBA)如何从变量变化的瞬间保持单元格值

(Excel VBA)如何从变量变化的瞬间保持单元格值,excel,vba,Excel,Vba,我已经创建了一个下拉菜单,允许我的用户从一个集合中选择,然后我在一个按钮启动的宏中引用该集合,以收集信息来完成一个表格。是否有一种方法可以在仅运行宏时将单元格锁定为下拉列表中的值。i、 e.当下拉选项更改时,我不希望已使用宏创建的行的值生效 如果我理解正确,您在单元格中有一个值(让我们使用A1,值为“10”)。运行宏时,希望此值不更改 只需在宏的开头添加如下内容: Dim constCell as Range, constVal as String Set constCell = Range("

我已经创建了一个下拉菜单,允许我的用户从一个集合中选择,然后我在一个按钮启动的宏中引用该集合,以收集信息来完成一个表格。是否有一种方法可以在仅运行宏时将单元格锁定为下拉列表中的值。i、 e.当下拉选项更改时,我不希望已使用宏创建的行的值生效

如果我理解正确,您在单元格中有一个值(让我们使用
A1
,值为“10”)。运行宏时,希望此值不更改

只需在宏的开头添加如下内容:

Dim constCell as Range, constVal as String
Set constCell = Range("A1")
constVal = constCell.Value

... 
' Put your other macro stuff here
...

' And just before the `End Sub`, put the value back inplace:
constCell.Value = constVal 'this resets the cell to the original value, after your other macro stuff has run.

你可以,但听起来像是一个复杂的方式做某事/更好地做它的另一种方式?你能张贴的宏?对于宏,为什么不添加一些逻辑,以将值粘贴为值而不是公式结束?