The reason your code is not working is due to the the overuse of the Range .Activate method. This is different from .Range.Select
in that it only makes a different cell in the selection the ActiveCell. If the worksheet's Selection object only encompasses a single cell or a range of cells outside of what you are activating, then yes you will will select a single cell. If it is within the current worksheet's selected cells the it will only transfer user control to that cell.
Select a range of cells on a worksheet. For the purposes of this example C3:E8. Depending upon how you have selectected the cells, C3 is most likely in a different colour state and holds the ActiveCell property for that worksheet. It will receive any user input.
Now tap Enter↵ a few times. You will see that the 'focus' (aka ActiveCell) changes as you tap the Enter key. While C3:E8 may be the worksheet's Selection property, the worksheet's ActiveCell property changes as you tap Enter↵.
If you are pasting an unknown number of cells into a target destination, you should pick a single cell in the upper-left corner of where you want the cells to reside. Having a target of multiple cells with one cell somewhere within the range as the active cell will not work unless by circumstance and circumstance is not a reliable programming paradigm.
In short, if you .Activate
a cell you will only be selecting a single cell if the cell you activate is outside the current selection. If you .Select
a cell the that is the only one selected and is the active cell on that worksheet. You cannot paste into a range of cells that is a different rows × columns size than the source unless it is a single cell.
Your code should work with a simple modification.
Sub Test()
Worksheets("Sheet2").Activate
ActiveSheet.Range("A1").Activate
Selection.Copy
Worksheets("Sheet1").Activate
ActiveSheet.Range("A1").SELECT '<~~ this is changed to .Select
ActiveCell.Offset(1, 1).Activate
ActiveSheet.PasteSpecial
End Sub
However, there may be better ways. Direct Copy and paste is a preferred alternative but if all you want is the Range.Value property then a direct value transfer is best.
'abbreviated Copy and Paste
Sub Test2()
With Worksheets("Sheet2")
.Range("A1").Copy _
Destination:=Worksheets("Sheet1").Range("A1").Offset(1, 1)
End With
End Sub
'direct value transfer
Sub Test3()
With Worksheets("Sheet1").Range("A1").Offset(1, 1)
.Value = Worksheets("Sheet2").Range("A1").Value
End With
End Sub
If you do not need to transfer cell formatting, the latter is preferred.
See How to avoid using Select in Excel VBA macros for more methods on getting away from relying on select and activate to accomplish your goals.