View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
[email protected] crferguson@gmail.com is offline
external usenet poster
 
Posts: 91
Default Paste data into another workbook but not overwriting originaldata

On Dec 13, 8:37 am, Me wrote:
Afternoon all,

Im trying to programmatically copy and paste from one workbook into another,
with two seperate bits of data pulled from seperate locations.
So i have an excel file with two tabs of data, i then want to copy and paste
the data and have them both end up in one sheet.
Hope that makes sense.

Thanks


Sounds like you have two workbooks, one with two tabs (the source
workbook) containing the info you want to copy and another (the
destination workbook) where you want the data to end up. Just
reference each workbook, copy the elements from the source and then
paste them into the destination. Here's a most basic example of
copying items in cell A1 of sheets 1 and 2 and then pasting them into
another workbook into cell A1 and B1 of sheet 1:

Private Sub Merge()
Dim s1 As String, s2 As String
Dim sD As String 'name of destination book
Dim wbS As Workbook 'source book
Dim wbD As Workbook 'destination book

'set the name of the destination workbook
sD = "yourbook.xls"
'get the workbook objects
Set wbS = ActiveWorkbook
Set wbD = Workbooks(sD)

'get the values from the source
s1 = wbS.Sheets(1).Range("A1").Value
s2 = wbS.Sheets(1).Range("A1").Value

'place the values in the destination
wbD.Sheets(1).Range("A1").Value = s1
wbD.Sheets(1).Range("B1").Value = s2

'clean up
Set wbS = Nothing
Set wbD = Nothing
End Sub

Hope that's what you were needing

Cory