0

我正在尝试在两个工作簿之间移动(不同长度的)范围。

Windows("Comp1.xlsx").Activate 'Open sheet to pull data from
Range("E2").Select 'Starting point is the same every time
Range(Selection, Selection.End(xlDown)).Select 'Select all data below
Application.CutCopyMode = False
Selection.Copy 'Copy range
Windows("Comps Proto.xlsm").Activate 'Sheet to be pasted into
Range("K12").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
    xlNone, SkipBlanks:=False, Transpose:=False 'Paste data into new sheet

为了在下一个工作簿中重复这个功能,我需要移除粘贴的选择。我已经尝试了一切,包括偏移量和Application.CutCopyMode = False. 不工作。

见下图:第一个粘贴周期以选定的范围结束。我想移动到标记并圈出开始的单元格。这是下一个范围将以与上述相同的方式粘贴的位置,冲洗并重复

图片

4

2 回答 2

0

我试图解决的主要问题是让光标单击粘贴的范围,以便我可以继续。我发现下面的代码很有帮助。这是另一个论坛上的原始帖子:https ://superuser.com/questions/342772/how-do-i-move-the-selection-down-one-row-in-excel-2007/342835

Dim ColNumber As Integer

ColNumber = Selection.Column
Range("K" & CStr(ColNumber)).Select 'Click off the pasted values
ActiveCell.End(xlDown).Select 'Equivalent of ctrl+down
ActiveCell.End(xlDown).Select 'Moves down through the range in picture
ActiveCell.Offset(2, 0).Select 'Moves selection to the "Start" point in picture above
于 2018-08-23T13:51:47.910 回答
0

从您的范围位置来看,它有跨越所有边界的空闲单元格。这允许使用方便的CurrentRegion属性。在我的代码中,我假设你有 5 个这样的块要复制。随意更改要复制到的位置。

Sub MoveCells()
    Dim x%, rng As Range
    Set rng = [E5].CurrentRegion
    '// Copy 5 blocks of cells
    Do
        '// Change target cell to the one you need
        rng.Copy Sheets(2).Cells(1, x + 1)
        '// Here we locate last cell in block of cells, offset two cells down
        '// and select CurrentRegion again
        Set rng = rng(rng.Cells.Count).Offset(2).CurrentRegion
        x = x + 1
    Loop While x <= 5
End Sub
于 2018-08-23T17:49:55.193 回答