连接使用VBA从单元中减去的细胞

发布于 2025-01-20 03:48:44 字数 480 浏览 1 评论 0原文

我希望将按钮连接到 i3 和 l3 中的单元格。因此,每当单元格 i3 中的数字与 l3 中的数字相加或相减时,总是从 500 美元开始减去。因此,如果 40 在单元格 i3 中,则单元格 l3 应读取为 460。如果 60 在单元格 i3 中,则单元格 l3 应读取 440。我已在下面添加了代码。我下面的代码现在只是从单元格 i3 中添加和减去。

输入图片此处描述

Sub Lower()
    Range("i3").Value = Range("i3").Value - 1
End Sub

Sub Higher()
    Range("i3").Value = Range("i3").Value + 1
End Sub

I am looking to connect the buttons to the cells in i3 and cell l3. So that whenever the number iin cell i3 is added or subtracted to the number in l3 is always subtracted from starting at 500 dollars. So if 40 is in cell i3 cell l3 should read for 460. If 60 is in cell i3 then cell l3 should read 440. I have added my code below. My code below right now just adds and subtracts from cell i3.

enter image description here

Sub Lower()
    Range("i3").Value = Range("i3").Value - 1
End Sub

Sub Higher()
    Range("i3").Value = Range("i3").Value + 1
End Sub

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如果没有你 2025-01-27 03:48:44

用i3的设置总额

是最简单的方法是使L3 = 500 -i3的公式。

如果您想在VBA中进行操作,请尝试以下操作:

Private Sub Worksheet_Change(ByVal Target As Range)
    Cells(3, 12) = 500 - Cells(3, 9)
End Sub

它使用更改触发Cell L3的计算。


将子与

标准命令按钮的命令按钮相关联,在设计模式下,右键单击每个按钮,然后单击分配宏。然后从列表中选择子。

对于ActiveX按钮,在设计模式下,右键单击按钮,然后单击查看代码(或只需双击命令按钮)。在添加的单击事件子中,将关联的代码移至新创建的代码。

示例:

Private Sub Lower_Click()
    Range("I3").Value = Range("I3").Value - 1
End Sub

注意:< / strong>子名称将 /必须匹配命令按钮的(名称)而不是字幕(显示的文本)。默认情况下,第一个命令按钮将是commandbutton1_click()

Setup Total Money with I3

The easiest way would be to have the formula of L3 = 500 - I3.

If you wish to do it in vba try this:

Private Sub Worksheet_Change(ByVal Target As Range)
    Cells(3, 12) = 500 - Cells(3, 9)
End Sub

It uses the change event of the worksheet to trigger a calculation of cell L3.


Associate Sub with Command Button

For standard command buttons, in design mode, right click each button and then click Assign Macro. Then select the sub from the list.

For ActiveX buttons, in design mode, right click the button and click View Code (or just double click the command button). In the added click event sub, move the associated code to the newly created one.

Example:

Private Sub Lower_Click()
    Range("I3").Value = Range("I3").Value - 1
End Sub

NOTE: The sub's name will / must match the command button's (name) not caption (displayed text). By default the first command button would be CommandButton1_Click().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文