View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
maryj maryj is offline
external usenet poster
 
Posts: 76
Default Code to insert data from another workbook

Thanks! This looks close. My only question is that the data that is being
copied is always going to be one more column to the right than the last time
this was run. Is there a way to tell it to look at the next available column?
It would be in the same row each time.

Thanks

"K Dales" wrote:

Mary:
Assuming both workbooks are open when the macro runs, you could add
something like this to the macro code (where CopySheet and CopyRange give the
sheet name and range of cells you want to copy, PasteSheet and PasteRange
give the sheet name/column where you want to insert the cells, and using
"Workbook A and "Workbook B" as your workbook names - this really needs to be
the name as it appears in the title bar):

Workbooks("Workbook A").Sheets(CopySheet).Range(CopyRange).Copy
Workbooks("Workbook
B").Sheets(PasteSheet).Range(PasteRange).Insert(xl ShiftToRight)
Workbooks("Workbook
B").Sheets(PasteSheet).Range(PasteRange).PasteSpec ial(xlPasteValues)

Hope this does what you need.
K Dales


"maryj" wrote:

In Workbook A, I have a macro that imports data from another source. This
data is added into the next available column. Up to now I have been going
into Workbook A and copying and pasting 2 cells from this new data into
pasting it into Workbook B. Prior to pasting this data into Workbook B, I
also manually insert 2 new cells so that the old data is moved one column to
the right. I'm looking for suggestions of code to automate this. Thank
you!!!!!!!!!!!
--
maryj