Ho Jun Hong
Ho Jun Hong

Reputation: 339

Outputs different although same cells are selected using different methods to cut and paste in vba?

Below are my codes and I want to cut and paste a range of cells. The code

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

has managed to gave me the correct output and pasted the range of cells I've selected on every worksheet from sheetnumber 2 to last sheetnumber but the code

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

only managed to cut and paste the range of cells onto my last sheet. Why is this the case even though both are selecting the same range of cells to cut and paste?

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

Upvotes: 1

Views: 34

Answers (1)

Sacru2red
Sacru2red

Reputation: 64

I am not sure understanding

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

This Range Express means "ActiveSheet.cells(26,6)" So, It is better to use it explicitly Like

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

Upvotes: 2

Related Questions