2017-04-26 57 views
0

我有一个宏按钮分配给Excel表格末尾的形状。 它打开用于向表中添加数据的用户表单。将形状移动到最后一行

问题是,形状不会随着每个新条目而向下移动,并最终位于表格的顶部。

形状被设置为与电池的举动,但也有未插入实际的行,只是数据添加到表的末尾..

我怎样才能使它与第一个空行与Excel的VBA移动?

+0

您应该在询问之前表现出努力。我建议你阅读[问]。 –

+0

对不起,我不是母语为英语的人,我会用我的语言写完美的。你对文本的改变对我来说没有什么意义...... 感谢您对它进行编辑,对不起,我很匆忙。 –

回答

0

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

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 
+0

Aww,谢谢。 完美作品 –

+0

不客气Daniel!很高兴它的工作。 – sktneer