PC Review


Reply
Thread Tools Rate Thread

Copy data from different columns of multiple sheets

 
 
Scott
Guest
Posts: n/a
 
      17th Dec 2009
I have to summarize the latest sales number from different offices, more than
40 of them. The numbers are sitting in one Excel file with each office having
one sheet. On each sheet the sales numbers for that office are listed
monthly. The latest number for some offices are for Nov, some Oct, and some
terminated offices with numbers as early as a couple of years ago.

Here is what I have to do: I have to go to each sheet (named "office 1" to
"office 50"), find the last column with data in that sheet and copy the
column to a new sheet (say Sheet "Summary"). In the new sheet, Column A for
data of Office 1, Column B for Office 2, etc.

Is there a way to program this process, other than copy-paste 50 times?

Thanks a lot.
 
Reply With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      17th Dec 2009
Scott,

This assumes a sheet called "Summary" already exists


Sub marine()
Dim MyCol As Long, x As Long
MyCol = Sheets("Summary").UsedRange.Columns.Count+1
For x = 1 To Worksheets.Count
If UCase(Left(Sheets(x).Name, 6)) = "OFFICE" Then
r = Sheets(x).UsedRange.Columns.Count
Sheets(x).Columns(r).Copy _
Destination:=Sheets("Summary").Cells(1, MyCol)
MyCol = MyCol + 1
End If
Next
End Sub


Mike

"Scott" wrote:

> I have to summarize the latest sales number from different offices, more than
> 40 of them. The numbers are sitting in one Excel file with each office having
> one sheet. On each sheet the sales numbers for that office are listed
> monthly. The latest number for some offices are for Nov, some Oct, and some
> terminated offices with numbers as early as a couple of years ago.
>
> Here is what I have to do: I have to go to each sheet (named "office 1" to
> "office 50"), find the last column with data in that sheet and copy the
> column to a new sheet (say Sheet "Summary"). In the new sheet, Column A for
> data of Office 1, Column B for Office 2, etc.
>
> Is there a way to program this process, other than copy-paste 50 times?
>
> Thanks a lot.

 
Reply With Quote
 
Scott
Guest
Posts: n/a
 
      17th Dec 2009
Mike,

Thank you very much. It works.

Scott

"Mike H" wrote:

> Scott,
>
> This assumes a sheet called "Summary" already exists
>
>
> Sub marine()
> Dim MyCol As Long, x As Long
> MyCol = Sheets("Summary").UsedRange.Columns.Count+1
> For x = 1 To Worksheets.Count
> If UCase(Left(Sheets(x).Name, 6)) = "OFFICE" Then
> r = Sheets(x).UsedRange.Columns.Count
> Sheets(x).Columns(r).Copy _
> Destination:=Sheets("Summary").Cells(1, MyCol)
> MyCol = MyCol + 1
> End If
> Next
> End Sub
>
>
> Mike
>
> "Scott" wrote:
>
> > I have to summarize the latest sales number from different offices, more than
> > 40 of them. The numbers are sitting in one Excel file with each office having
> > one sheet. On each sheet the sales numbers for that office are listed
> > monthly. The latest number for some offices are for Nov, some Oct, and some
> > terminated offices with numbers as early as a couple of years ago.
> >
> > Here is what I have to do: I have to go to each sheet (named "office 1" to
> > "office 50"), find the last column with data in that sheet and copy the
> > column to a new sheet (say Sheet "Summary"). In the new sheet, Column A for
> > data of Office 1, Column B for Office 2, etc.
> >
> > Is there a way to program this process, other than copy-paste 50 times?
> >
> > Thanks a lot.

 
Reply With Quote
 
Gord Dibben
Guest
Posts: n/a
 
      17th Dec 2009
Scott

Be careful with Activesheet.usedrange.

May not be what you think it is.

Test...............

Run this........MsgBox ActiveSheet.UsedRange.Columns.Count + 1

Note the number returned.

Go to last column. Then go next blank column and enter a bunch of text in
several cells.

Clear Contents of these cells.........do not delete entire
columns......clear or delete cell contents only.

Save then re-open workbook.

Run...........MsgBox ActiveSheet.UsedRange.Columns.Count + 1

Note the number returned.

Now run this..........

MsgBox ActiveSheet.Cells(ActiveCell.Row, Columns.Count).End(xlToLeft).Column


Gord Dibben MS Excel MVP

On Thu, 17 Dec 2009 09:07:02 -0800, Scott <(E-Mail Removed)>
wrote:

>Mike,
>
>Thank you very much. It works.
>
>Scott
>
>"Mike H" wrote:
>
>> Scott,
>>
>> This assumes a sheet called "Summary" already exists
>>
>>
>> Sub marine()
>> Dim MyCol As Long, x As Long
>> MyCol = Sheets("Summary").UsedRange.Columns.Count+1
>> For x = 1 To Worksheets.Count
>> If UCase(Left(Sheets(x).Name, 6)) = "OFFICE" Then
>> r = Sheets(x).UsedRange.Columns.Count
>> Sheets(x).Columns(r).Copy _
>> Destination:=Sheets("Summary").Cells(1, MyCol)
>> MyCol = MyCol + 1
>> End If
>> Next
>> End Sub
>>
>>
>> Mike
>>
>> "Scott" wrote:
>>
>> > I have to summarize the latest sales number from different offices, more than
>> > 40 of them. The numbers are sitting in one Excel file with each office having
>> > one sheet. On each sheet the sales numbers for that office are listed
>> > monthly. The latest number for some offices are for Nov, some Oct, and some
>> > terminated offices with numbers as early as a couple of years ago.
>> >
>> > Here is what I have to do: I have to go to each sheet (named "office 1" to
>> > "office 50"), find the last column with data in that sheet and copy the
>> > column to a new sheet (say Sheet "Summary"). In the new sheet, Column A for
>> > data of Office 1, Column B for Office 2, etc.
>> >
>> > Is there a way to program this process, other than copy-paste 50 times?
>> >
>> > Thanks a lot.


 
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
Excel: Merging data from multiple sheets / different columns VPCPG Windows XP 3 20th Dec 2008 05:09 PM
Copy data to multiple sheets HighlandRoss Microsoft Excel Worksheet Functions 2 27th Feb 2008 08:38 PM
how to compare two columns on two sheets and copy associated data from one sheet to the other? meghantrus@hotmail.com Microsoft Excel Programming 1 22nd Jun 2007 04:12 PM
how to compare two columns on two sheets and copy associated data from one sheet to the other? meghantrus@hotmail.com Microsoft Excel Worksheet Functions 2 22nd Jun 2007 03:40 PM
Copy data from multiple sheets into new sheet =?Utf-8?B?QW5naWU=?= Microsoft Excel Worksheet Functions 0 5th Jun 2007 10:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:04 AM.