在excel vba中复制行内容

我从来没有做过任何的Excel VBA程序。 我想写一个VBA代码,这将允许我复制一行,包括第一列的button到一个新的行。

我能够复制行内容,但不能复制button。 请帮忙

我的excel如下所示: –

button|| DATA || DATA || DATA

图片链接: https : //ibb.co/cijovv

这个代码我写到目前为止:=

Dim Lr As Integer Dim newLr As Integer Dim lim As String Lr = range("A" & Rows.Count).End(xlUp).Row 'Searching last row in column A newLr = Lr + 1 lim = "B" & newLr & ":" + "D" & newLr Rows(Lr).Copy Rows(newLr).Insert Shift:=x1Down range(lim).ClearContents 

试试像这样…

 Dim Lr As Integer Dim newLr As Integer Dim lim As String Lr = Range("A" & Rows.Count).End(xlUp).Row 'Searching last row in column A newLr = Lr + 1 lim = "B" & newLr & ":" + "D" & newLr Application.CopyObjectsWithCells = True Rows(Lr).Copy Rows(newLr).Insert Shift:=xlDown Range(lim).ClearContents Application.CopyObjectsWithCells = False 

如果你在A5有一个ActiveX命令button,你可以尝试这样的事情…

 Dim Lr As Integer Dim newLr As Integer Dim lim As String Dim oleObj As OLEObject, oleCopy As OLEObject Lr = Range("A" & Rows.Count).End(xlUp).Row 'Searching last row in column A newLr = Lr + 1 lim = "B" & newLr & ":" + "D" & newLr Rows(Lr).Copy Rows(newLr).Insert Shift:=xlDown Application.CutCopyMode = 0 For Each oleObj In ActiveSheet.OLEObjects If oleObj.TopLeftCell.Row = Lr Then Set oleCopy = oleObj.Duplicate With oleCopy .Left = Range("A" & newLr).Left .Top = Range("A" & newLr).Top End With oleObj.Delete Exit For End If Next oleObj Range(lim).ClearContents