首页 > 解决方案 > 尽管使用不同的方法在vba中剪切和粘贴相同的单元格,但输出不同?

问题描述

下面是我的代码,我想剪切和粘贴一系列单元格。编码

Currentsheet.Range("F26:G26").Cut Destination:=Currentsheet.Range("F25:G25") 

设法给了我正确的输出并粘贴了我在每个工作表上选择的单元格范围,从 sheetnumber 2 到最后一个 sheetnumber 但代码

Currentsheet.Range(Cells(26, 6), Cells(26, 6 + 1)).Cut Destination:=Currentsheet.Range(Cells(25, 6), Cells(25, 6 + 1))

只设法将单元格范围剪切并粘贴到我的最后一张纸上。即使两者都选择相同范围的单元格进行剪切和粘贴,为什么会出现这种情况?

For sheetnumber = 2 To ThisWorkbook.Sheets.Count
    Set Currentsheet = ThisWorkbook.Sheets(sheetnumber)

    For Column = 4 To Currentsheet.Cells(11, Columns.Count).End(xlToLeft).Column
        If Currentsheet.Cells(25, Column) > 300 And Currentsheet.Cells(25, Column) < 500 Then
            Currentsheet.Rows(25).Insert shift:=xlShiftDown
            'Currentsheet.Range(Cells(26, 6), Cells(26, 6 + 1)).Cut Destination:=Currentsheet.Range(Cells(25, 6), Cells(25, 6 + 1))
            Currentsheet.Range("F26:G26").Cut Destination:=Currentsheet.Range("F25:G25")
        End If
    Next Column
Next sheetnumber

标签: excelvba

解决方案


我不确定理解

Currentsheet.Range(Cells(26, 6), Cells(26, 6 + 1))
Cells(26,6)

这个 Range Express 的意思是“ActiveSheet.cells(26,6)”所以,最好明确地使用它 Like

Currentsheet.Range(Currentsheet.Cells(26, 6), Currentsheet.Cells(26, 6 + 1))

推荐阅读