【问题标题】:Move a shape to the last row将形状移动到最后一行
【发布时间】:2017-04-27 21:58:58
【问题描述】:

我有一个宏按钮分配给 Excel 表格末尾的形状。 它会打开一个用户表单,用于向表中添加数据。

问题是形状不会随着每个新条目向下移动,最终会出现在表格顶部。

形状设置为随单元格移动,但没有插入实际的行,只是将数据添加到表的末尾。..

如何使用 Excel-VBA 使其与第一个空行一起移动?

【问题讨论】:

  • 你应该在询问之前表现出努力。我建议你阅读How to Ask
  • 对不起,我不是以英语为母语的人,我会用我的语言写出完美的。您对文本的更改对我来说没有多大意义...感谢您的编辑,抱歉没有关注,我很着急。

标签: excel shape vba


【解决方案1】:

将此代码放在标准模块上,在将数据写入工作表后,调用此代码,将按钮(形状)放置到第一个空行。 根据您的要求更改它。

Sub MoveButton()
Dim ws As Worksheet
Dim lr As Long
Dim buttonCell As Range
Dim shp As Shape
Set ws = Sheets("Sheet1")   'Sheet where shape is inserted
lr = ws.Cells(Rows.Count, 1).End(xlUp).Row + 1  'first empty row in column A
Set buttonCell = ws.Cells(lr, "A")  'setting the cell where button will be placed
Set shp = ws.Shapes("myShape")  'name of the shape is "myShape", change it as per your requirement
'set the shape dimensions
With shp
    .Left = buttonCell.Left
    .Top = buttonCell.Top
End With
End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-28
    • 1970-01-01
    • 1970-01-01
    • 2022-06-28
    相关资源
    最近更新 更多