uau007_2137
09-20-2012, 02:07 AM
How to copy range and paste in same range but in another workbook
Hi All,
I am new to this forum. Need help on my coding.
I am trying to copy an already selected range of cells in a workbook and pasting them into another workbook in the same range as the source workbook. I wrote the following code but it is stuck where I try to select the named range in the destination workbook.
Where am I going wrong?:banghead:
++++++++++++++++++
Private Sub Send_Hour_Val_Click()
'Definitions:
Dim flPath As String
Dim SelRange As Range
Set SelRange = Selection
'path:
flPath = "C:\Documents and Settings\mngr\My Documents\testing sheet.xlsx"
'copy selection:
SelRange.Copy
'open destination workbook:
Workbooks.Open flPath
'activate destination sheet
Sheets("Testing").Activate
'select destination range
Range("SelRange").Select
'paste special, save and close
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ActiveWorkbook.Save
ActiveWorkbook.Close
End Sub
+++++++++++++++
Hi All,
I am new to this forum. Need help on my coding.
I am trying to copy an already selected range of cells in a workbook and pasting them into another workbook in the same range as the source workbook. I wrote the following code but it is stuck where I try to select the named range in the destination workbook.
Where am I going wrong?:banghead:
++++++++++++++++++
Private Sub Send_Hour_Val_Click()
'Definitions:
Dim flPath As String
Dim SelRange As Range
Set SelRange = Selection
'path:
flPath = "C:\Documents and Settings\mngr\My Documents\testing sheet.xlsx"
'copy selection:
SelRange.Copy
'open destination workbook:
Workbooks.Open flPath
'activate destination sheet
Sheets("Testing").Activate
'select destination range
Range("SelRange").Select
'paste special, save and close
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ActiveWorkbook.Save
ActiveWorkbook.Close
End Sub
+++++++++++++++