将形状移动到最后一行

Move a shape to the last row

我有一个宏按钮分配给 Excel table 末尾的形状。 它打开一个用于向 table.

添加数据的用户表单

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

形状设置为随单元格一起移动,但没有实际插入行,只是数据添加到 table..

的末尾

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

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

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