将一系列单元格剪切并粘贴到选定的目标位置

时间:2019-03-29 13:40:34

标签: excel vba range paste cut

我想剪切并粘贴一定范围的单元格(例如A2:D2到B1:E1),然后对692行重复此过程。

enter image description here

我一直试图在宏中执行此操作,但未成功。

Sub cut_paste() 
    Dim nr As Integer 
    For nr = 1 To 692 
        Range("A" & nr).Select 
        Selection.Cut 
        Range("B" & nr).Select 
        ActiveSheet.Paste 
        Range("B" & nr).Select 
        Selection.Cut 
        Range("C" & nr).Select 
        ActiveSheet.Paste 
        Range("C" & nr).Select 
        Selection.Cut 
        Range("D" & nr).Select 
        ActiveSheet.Paste 
        Range("D" & nr).Select 
        Selection.Cut 
        Range("E" & nr).Select 
        ActiveSheet.Paste 
    Next nr 
End Sub
  

错误4001

enter image description here

enter image description here

2 个答案:

答案 0 :(得分:2)

尝试:

Map<Sale, Integer> map = list.stream()
        .collect(Collectors.groupingBy(o -> o, Collectors.summingInt(Sale::getField4)));

答案 1 :(得分:1)

首先,您为第2到692行创建一个循环:

For i = 2 to 692
    'code to execute in the loop goes here
Next i

然后在该循​​环中复制/粘贴

For i = 2 to 692
    Sheet1.Range("A" & i & ":D" & i).Copy Destination:=Sheet1.Range("B" & i - 1 & ":E" & i - 1)
Next i