Hi All,
It's been a few years since I've written any VBA and I'm having trouble waking up again. I'm knocking my head against a brick wall trying to write what I thought would be quite a simple Sub to copy a range from one sheet and paste it (values only) to another sheet.
Here's how I want to call the Sub:
This means:
Where am I going wrong? Or does someone have a copy and paste sub ready to go that doesn't involve physically switching sheets?
Thanks very much in advance for any assistance.
It's been a few years since I've written any VBA and I'm having trouble waking up again. I'm knocking my head against a brick wall trying to write what I thought would be quite a simple Sub to copy a range from one sheet and paste it (values only) to another sheet.
Here's how I want to call the Sub:
VBA Code:
Call CopyPasteValues("Your Data", "A1", 102, 13, "Results", "C1")
This means:
- copy a range in the "Your Data" sheet that starts in A1 and is 102 rows x 13 columns
- paste it (as values, not formulae) to "Results" sheet, starting in C1 (top left)
Where am I going wrong? Or does someone have a copy and paste sub ready to go that doesn't involve physically switching sheets?
Thanks very much in advance for any assistance.
VBA Code:
Sub CopyPasteValues(strSourceSheet As String, strSourceTopLeft As String, lNumRows As Long, lNumCols As Long, strDestSheet As String, strDestTopLeft As String)
Sheets(strSourceSheet).Range(Range(strSourceTopLeft), Range(strSourceTopLeft).Offset(lNumRows - 1, lNumCols - 1)).Copy
Sheets(strDestSheet).Range(strDestTopLeft).PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
End Sub