Excel VBA:获取单击按钮的行 [英] Excel VBA: getting row of clicked button

查看:49
本文介绍了Excel VBA:获取单击按钮的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Excel 中创建一个按钮,将特定范围的单元格从活动工作簿复制到另一个工作簿.当我指定一个固定范围时,此范围的复制效果很好,但我对如何找出单击按钮的行感到困惑.

I am trying to make a button in Excel which copies a certain range of cells from the active workbook to another workbook. The copying of this range works perfectly when I specify a fixed range, but I am stumped on how to figure out the row of the clicked button.

每行包含 7 个左右的单元格,第 8 个单元格包含一个带有宏的形状(按钮).当用户按下此按钮时,需要复制与包含按下按钮的行位于同一行的 7 个单元格.

Every row contains 7 or so cells, and the 8th cell contains a shape with a macro attached to it (the button). When the user presses this button the 7 cells on the same row as the row containing the pressed button need to be copied.

使用 ActiveCell 没有用,因为按下按钮实际上并没有将该单元格设置为活动状态.我搜索了很多,但似乎找不到如何获得这个值.一旦我有了点击按钮的行号,我就可以自己计算其余的了.

Using ActiveCell is of no use, since pressing the button doesn't actually set that cell as active. I searched around a lot but I can't seem to find how to obtain this value. Once I have the row number of the clicked button I can figure the rest out on my own.

推荐答案

每个 Shape 都有 TopLeftCell 属性.它包含一个单元格,形状的左上角位于该单元格中.

Each Shape has TopLeftCell property. It contains a cell within which the top left corner of the shape resides.

这篇关于Excel VBA:获取单击按钮的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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