繁体   English   中英

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

[英](Excel VBA) How to maintain a cell value from an instant of a changing variable

我创建了一个下拉菜单,允许我的用户从集合中进行选择,然后在按钮启动的宏中引用该集合以收集信息以完成表格。 有没有一种方法可以在仅运行宏的那一刻将单元格锁定为下拉菜单中的值。 即我不希望更改下拉选项时影响已经用宏创建的行的值。

如果我理解正确,那么您在单元格中就有一个值(让我们使用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.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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