复制和插入复制的单元格

复制和插入复制的单元格

本文介绍了Excel VBA宏 - 复制和插入复制的单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎不能做这件事情。我一直坚持

 行(rng 5)。选择

我想要做的是复制活动单元格的行,并将复制的单元格插入活动单元格下方5行的行。

  Sub CopyConcatenate()


Dim ws As Worksheet
Dim rng As Range

设置rng = ActiveCell.Rows

rng.Select
Selection.Copy
行(rng 5)。选择
Selection.Insert Shift: = xlDown

End Sub


解决方案



这是你正在尝试的吗?

  Sub CopyConcatenate()
Dim ws As Worksheet
Dim rng As Range

'~~>将此设置为相关工作表
设置ws = ThisWorkbook.Sheets(Sheet1)

带有ws
'~~>设置范围
设置rng = .Rows(ActiveCell.Row)

'~~>复制范围
rng.Copy

'~~>插入范围
rng.Offset(5).Insert Shift:= xlDown

'~~>清除剪贴板。更重要的是删除
'~~>蚂蚁像边框
Application.CutCopyMode = False
结束
End Sub


I can't seem to make to this work. I keep getting stuck on

    Rows(rng 5).Select

What I am trying to do is copy the row of the active cell and inserting the copied cell in a row that is 5 rows below the active cell.

Sub CopyConcatenate()


    Dim ws As Worksheet
    Dim rng As Range

    Set rng = ActiveCell.Rows

    rng.Select
    Selection.Copy
    Rows(rng 5).Select
    Selection.Insert Shift:=xlDown

End Sub
解决方案

Untested.

Is this what you are trying?

Sub CopyConcatenate()
    Dim ws As Worksheet
    Dim rng As Range

    '~~> Set this to the relevant worksheet
    Set ws = ThisWorkbook.Sheets("Sheet1")

    With ws
        '~~> Set your range
        Set rng = .Rows(ActiveCell.Row)

        '~~> Copy the range
        rng.Copy

        '~~> Insert the range
        rng.Offset(5).Insert Shift:=xlDown

        '~~> Clear the clipboard. More importantly remove the
        '~~> ant like borders
        Application.CutCopyMode = False
    End With
End Sub

这篇关于Excel VBA宏 - 复制和插入复制的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 22:12