在excel vba中复制行内容

时间:2017-05-19 18:23:45

标签: excel vba excel-vba

我从未做过任何excel vba计划。我想写一个vba代码,它允许我将包含第一列按钮的行复制到新行。

我可以复制行内容但无法复制按钮。请帮忙

我的擅长如下: -

按钮|| || 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

1 个答案:

答案 0 :(得分:0)

尝试这样......

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命令按钮,您可以尝试这样的事情......

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