Day 9 VBA Hero – Copy and Paste Cells


My hatred for copying and pasting is well-documented.

This is what I really wanted to do when I started to code.

Copy and paste.

Everything else was just extra.
There are a few ways of writing a copy and paste.

The way that makes sense when reading it, would be like this.

Sub CopyPaste()

Sheets(“Sheet1”).Range(“C3”).Copy
Sheets(“Sheet2”).Range(“H3”).PasteSpecial

End Sub

However, if you like the idea of doing the copy and paste in one line, then:

Sub CopyPaste()

Sheets(“Sheet1”).Range(“C3”).Copy Sheets(“Sheet2”).Range(“H3”)

End Sub

If you are trying to copy formulas from one cell to another

Sub CopyPaste()

Sheets(“Sheet1”).Range(“C3”).Copy
Sheets(“Sheet2”).Range(“H3”).PasteSpecial xlPasteFormulas

End Sub

If you are trying to copy and paste values from one cell with formulas to another cell so that only the values stick

Sub CopyPaste()

Sheets(“Sheet1”).Range(“C3”).Copy
Sheets(“Sheet2”).Range(“H3”).PasteSpecial xlPasteValues

End Sub

The last two methods to copy and paste can also be done in one line, however, I think that it is too difficult to read for me.

Sub CopyPaste()

Sheets(“Sheet1”).Range(“C3”).Copy: Sheets(“Sheet2”).Range(“H3”).PasteSpecial Paste:=xlPasteValues

End Sub

Today’s homework is to copy and paste from one sheet to another. But with multiple cells to copy and not just one cell

Verified by MonsterInsights