vba call: value display without pressing play button

时间:2017-06-19 14:00:20

标签: excel-vba vba excel

why I have to press run button every time to run every vba code. Example I would like to sum a1+b1, result show in C1. Then a2+b2 result shows in C2.

But this code not run automatically. I have to click play button every time. Is there any way so that when I put value in A1 or B1 result shows in C1 without pressing macro button or play button (in VBA Editor).

I want to just run it like excel formula

1 个答案:

答案 0 :(得分:0)

您必须将代码放在工作表的Worksheet_change事件中,并且不要忘记禁用应用程序事件,否则它是无限循环:

private sub Worksheet_Change(ByVal Target as Range)
    Application.EnableEvents = False
       '
       ' call your update procedure
       '
    Application.EnableEvents = True
end sub

在您想要的工作表上使用VBA编辑器:

enter image description here