简体   繁体   English

如何使用Excel中的按钮在工作表中运行计算

[英]How to run a calculation in a sheet using button in excel

I am trying to create an form control or activex command button to change a series of values to a particular calculation. 我正在尝试创建一个窗体控件或activex命令按钮,以将一系列值更改为特定的计算。

My button is on a sheet named "Sheet 2" and the calculation needs to happen on a sheet named "Whatif back". 我的按钮在名为“ Sheet 2”的工作表上,计算需要在名为“ Whatif back”的工作表上进行。

When i press the button, C2 in "Whatif back" must be calculated with C27 in "Sheet 2". 当我按下按钮时,“ Whatif back”中的C2必须与“ Sheet 2”中的C27一起计算。

My code is: 我的代码是:

Sub Sheet2_Button18_Click()
Sheets("Whatif back").Range("C2")=(10000+Sheets("Sheet2").Range(C27))
End Sub

I am getting a compile error. 我收到一个编译错误。 Please help. 请帮忙。

Thank you, Shyam 谢谢Shyam

with an ActiveX button named after "Sheet2_Button18" in worksheet "Sheet2" you use this: 与工作表“ Sheet2”中以“ Sheet2_Button18”命名的ActiveX按钮配合使用:

Sub Sheet2_Button18_Click()
    Sheets("Whatif back").Range("C2") = 10000 + Range("C27")
End Sub

Nice to know what compile error you're getting, but try: Range("C27") instead of Range(C27) 很高兴知道您遇到什么编译错误,但请尝试:Range(“ C27”)而不是Range(C27)

(this should be a comment but I don't have rep yet) (这应该是评论,但我没有代表)

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

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