Excel:相对单元增量计数器按钮 [英] Excel: Increment Counter Button of Relative Cell

查看:397
本文介绍了Excel:相对单元增量计数器按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



但是,我不想增加一个绝对引用的单元格,而是要在Excel中添加一个按钮相对于按钮位置增加单元格的值。



这是迄今为止使用的代码类型,但是找到事件对象的关键问题位置证明很难...

  Sub increment_value()
this.Offset(0,-2).Value = this.Offset(0,-2).Value + 1
End Sub

是我想要做的(仅仅是示例 - >按钮在D5中增加B5由1. 相对是关键!):





Sub想:有没有相当于Javascript关键字的Excel:这个

解决方案

按钮是一个ActiveX,您可以添加以下代码:

  Private Sub CommandButton1_Click()
Me.CommandButton1.TopLeftCell.Offset(0,-2)= _
Me.CommandButton1.TopLeftCell.Offset(0,-2)+ 1
End Sub

其中:



我。 是指按钮所在的工作表。



.CommandButton1。 本身



.TopLeftCell 是返回单元格的 Range对象的属性您的按钮位于TopLeft的角落。所以,当你在表格中找到它时,请确定。



经过测试!


In Excel, I want to have a button to click that will increment the value of a cell.

However, rather than increment an absolutely referenced cell, I want to increment the value of a cell relative to the button location.

This is the type of code I am working with so far, however the key question of finding the event object location is proving difficult...

Sub increment_value()
this.Offset(0, -2).Value = this.Offset(0, -2).Value + 1
End Sub

This is what I want it to do (example only -> button in D5 increment B5 by 1. Relative is the key though!):

Sub thought: Is there an Excel equivalent to the Javascript keyword: this?

解决方案

If your button is an ActiveX one you could add the following code to it:

Private Sub CommandButton1_Click()
    Me.CommandButton1.TopLeftCell.Offset(0, -2) = _
            Me.CommandButton1.TopLeftCell.Offset(0, -2) + 1
End Sub

Where:

Me. refers to sheet where button is located.

.CommandButton1. refers to itself

.TopLeftCell is property which returns Range object of the cell where is located TopLeft corner of your button. So, be precise when you locate it in the sheet.

Tried and tested!

这篇关于Excel:相对单元增量计数器按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆