PC Review


Reply
Thread Tools Rate Thread

Copy between spreadsheets

 
 
jcrmeyer@gmail.com
Guest
Posts: n/a
 
      22nd Jan 2007
Hi there, I'm a bit of a newbie with macros so was hoping someone might
be able to help me out with this one:

I have a master spreadsheet (master.xls) that has a header row and then
a series or rows containing data in columns A thru G. Each row
corresponds to data taken from a number of other spreadsheets
(order1.xls, order2.xls etc).

Basically I need a macro run in master.xls that will copy data from one
of the order spreadsheets and append it to the rows already there in
master, i.e. find the last row containing data and adding it after
that.

Data in the order.xls workbooks has a fixed format A1:A3 and then a
variable number of rows A55 (A66, A77 etc). So when copied into
Master.xls A55, A66 etc is copied to first empty row in columns D
thru G, and for each of those the same A1:A3 is transposed to columns A
thru C. So it ends up something like this:

A1 A2 A3 A5 B5 C5 D5
A1 A2 A3 A6 B6 C6 D6
A1 A2 A3 A7 B7 C7 D7
etc

I'm okay with opening workbooks, making them active etc. What I need is
the code that will find the first empty row in Master.xls and the code
to copy (a loop I guess) that will move date from order.xls to
master.xls and know when to stop when it reaches the last filled row in
order.xls.

Thanks!

 
Reply With Quote
 
 
 
 
jcrmeyer@gmail.com
Guest
Posts: n/a
 
      22nd Jan 2007
Sorry that should have been "move data" not "move date" in my last
sentence!

(E-Mail Removed) wrote:
> Hi there, I'm a bit of a newbie with macros so was hoping someone might
> be able to help me out with this one:
>
> I have a master spreadsheet (master.xls) that has a header row and then
> a series or rows containing data in columns A thru G. Each row
> corresponds to data taken from a number of other spreadsheets
> (order1.xls, order2.xls etc).
>
> Basically I need a macro run in master.xls that will copy data from one
> of the order spreadsheets and append it to the rows already there in
> master, i.e. find the last row containing data and adding it after
> that.
>
> Data in the order.xls workbooks has a fixed format A1:A3 and then a
> variable number of rows A55 (A66, A77 etc). So when copied into
> Master.xls A55, A66 etc is copied to first empty row in columns D
> thru G, and for each of those the same A1:A3 is transposed to columns A
> thru C. So it ends up something like this:
>
> A1 A2 A3 A5 B5 C5 D5
> A1 A2 A3 A6 B6 C6 D6
> A1 A2 A3 A7 B7 C7 D7
> etc
>
> I'm okay with opening workbooks, making them active etc. What I need is
> the code that will find the first empty row in Master.xls and the code
> to copy (a loop I guess) that will move date from order.xls to
> master.xls and know when to stop when it reaches the last filled row in
> order.xls.
>
> Thanks!


 
Reply With Quote
 
merjet
Guest
Posts: n/a
 
      22nd Jan 2007
Di iRow As Long

'find last filled cell in column A
iRow =
Workbook("Master.xls").Sheets("Sheet1").Range("A1").end(xlDown).Row
'so iRow +1 would be the next empty row in column A
'do similar line in order.xls and use result to set last row of loop

Hth,
Merjet

 
Reply With Quote
 
merjet
Guest
Posts: n/a
 
      22nd Jan 2007
Oops. Workbooks, not Workbook

Merjet

 
Reply With Quote
 
jcrmeyer@gmail.com
Guest
Posts: n/a
 
      22nd Jan 2007
Okay, I've got it working. But I think there might be neater ways of
doing it. Because one range of data has to be transposed I'm copying
over in two stages. It would be good if I could do it in a single step
but I'm not sure how.

Also could someone tell me how I select a range for copying that is not
contiguous, i.e below I use
Range(Cells(rw, 1), Cells(rw, 20)).Select, but actually I only want to
select then copy the first cell and the last 15 cells in the row
skipping cells 2-5.



Workbooks("order.xls").Sheets("Orderform").Activate
Dim rw As Long
rw = 17

Do Until ActiveSheet.Cells(rw, 1) = ""

Range(Cells(8, 2), Cells(12, 2)).Select
Application.CutCopyMode = False
Selection.Copy

Workbooks("master.xls").Sheets("Orders").Activate
Range("F1").End(xlDown).Offset(1, -5).Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats,
Operation:= _
xlNone, SkipBlanks:=False, Transpose:=True

Workbooks("order.xls").Sheets("Orderform").Activate
Range(Cells(rw, 1), Cells(rw, 20)).Select
Application.CutCopyMode = False
Selection.Copy

Workbooks("master.xls").Sheets("Orders").Activate
Range("F1").End(xlDown).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats,
Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False

Workbooks("order.xls").Sheets("Orderform").Activate

rw = rw + 1

Loop

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy from one source to multiple spreadsheets msdrolf Microsoft Excel Programming 1 23rd Nov 2009 05:59 PM
copy equations between spreadsheets =?Utf-8?B?R3JlZW5iZWFyZA==?= Microsoft Excel Worksheet Functions 2 8th Mar 2007 04:57 AM
How do I copy spreadsheets with charts? =?Utf-8?B?SGVsZ2U=?= Microsoft Excel Charting 2 11th Aug 2006 12:02 PM
Copy range from 600 spreadsheets =?Utf-8?B?U25vd3NyaWRl?= Microsoft Excel Programming 2 10th Feb 2006 09:43 AM
Copy Spreadsheets =?Utf-8?B?QXVyb3Jh?= Microsoft Excel Misc 1 1st Feb 2006 04:15 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:14 AM.