PC Review


Reply
Thread Tools Rate Thread

copy data of different range to other sheets

 
 
sutha
Guest
Posts: n/a
 
      5th Dec 2008
I HAVE A SHEET WITH P&L FOR 100 COMPANIES ONE BELOW ANOTHER. EACH P&L IS SAME
IN SIZE( 20 RAWS)

Can someone please help with a sub that will copy each p&l in different
sheet and name each sheet with the 1st word found in the begining of the
range (Eg; raw 1
company name "xxx")
 
Reply With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      5th Dec 2008
Hi,

You didn't say where you want the data pasting so this pastes ot ti row 1 in
the addded sheet. Alt+F11 to open VB editor. Right click 'This workbook' and
insert module and paste this code in and run it. It assumes your P&L data are
on sheet 1

Sub Liminal()
lastrow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
Set myrange = Sheets("Sheet1").Range("A1:A" & lastrow)
For Each c In myrange
ShName = Left(c.Value, InStr(c.Value, " ") - 1)
Set c = c.Resize(, 20)
c.Copy
Worksheets.Add After:=ActiveSheet
ActiveSheet.Name = ShName
Range("A1").PasteSpecial
Next
End Sub

Mike

"sutha" wrote:

> I HAVE A SHEET WITH P&L FOR 100 COMPANIES ONE BELOW ANOTHER. EACH P&L IS SAME
> IN SIZE( 20 RAWS)
>
> Can someone please help with a sub that will copy each p&l in different
> sheet and name each sheet with the 1st word found in the begining of the
> range (Eg; raw 1
> company name "xxx")

 
Reply With Quote
 
sutha
Guest
Posts: n/a
 
      5th Dec 2008
Hi Mike,
Thanks for your quick reply.i am geting an error message" invalid proceedure
call or argument'.
Sutha

"Mike H" wrote:

> Hi,
>
> You didn't say where you want the data pasting so this pastes ot ti row 1 in
> the addded sheet. Alt+F11 to open VB editor. Right click 'This workbook' and
> insert module and paste this code in and run it. It assumes your P&L data are
> on sheet 1
>
> Sub Liminal()
> lastrow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
> Set myrange = Sheets("Sheet1").Range("A1:A" & lastrow)
> For Each c In myrange
> ShName = Left(c.Value, InStr(c.Value, " ") - 1)
> Set c = c.Resize(, 20)
> c.Copy
> Worksheets.Add After:=ActiveSheet
> ActiveSheet.Name = ShName
> Range("A1").PasteSpecial
> Next
> End Sub
>
> Mike
>
> "sutha" wrote:
>
> > I HAVE A SHEET WITH P&L FOR 100 COMPANIES ONE BELOW ANOTHER. EACH P&L IS SAME
> > IN SIZE( 20 RAWS)
> >
> > Can someone please help with a sub that will copy each p&l in different
> > sheet and name each sheet with the 1st word found in the begining of the
> > range (Eg; raw 1
> > company name "xxx")

 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      5th Dec 2008
on which line?

"sutha" wrote:

> Hi Mike,
> Thanks for your quick reply.i am geting an error message" invalid proceedure
> call or argument'.
> Sutha
>
> "Mike H" wrote:
>
> > Hi,
> >
> > You didn't say where you want the data pasting so this pastes ot ti row 1 in
> > the addded sheet. Alt+F11 to open VB editor. Right click 'This workbook' and
> > insert module and paste this code in and run it. It assumes your P&L data are
> > on sheet 1
> >
> > Sub Liminal()
> > lastrow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
> > Set myrange = Sheets("Sheet1").Range("A1:A" & lastrow)
> > For Each c In myrange
> > ShName = Left(c.Value, InStr(c.Value, " ") - 1)
> > Set c = c.Resize(, 20)
> > c.Copy
> > Worksheets.Add After:=ActiveSheet
> > ActiveSheet.Name = ShName
> > Range("A1").PasteSpecial
> > Next
> > End Sub
> >
> > Mike
> >
> > "sutha" wrote:
> >
> > > I HAVE A SHEET WITH P&L FOR 100 COMPANIES ONE BELOW ANOTHER. EACH P&L IS SAME
> > > IN SIZE( 20 RAWS)
> > >
> > > Can someone please help with a sub that will copy each p&l in different
> > > sheet and name each sheet with the 1st word found in the begining of the
> > > range (Eg; raw 1
> > > company name "xxx")

 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      5th Dec 2008
Hi,

I just replicated that error on this like

ShName = Left(c.Value, InStr(c.Value, " ") - 1)

But the problem is on these 2 lines

lastrow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
Set myrange = Sheets("Sheet1").Range("A1:A" & lastrow)

Change "Sheet1" on both these lines to the actual sheet name that contains
your original data. Note the sheet name must be in quotes.

In addition change "A" in both these lines to the first column of you P&L
data, like wise the column leter must be in quotes.

Mike

"sutha" wrote:

> Hi Mike,
> Thanks for your quick reply.i am geting an error message" invalid proceedure
> call or argument'.
> Sutha
>
> "Mike H" wrote:
>
> > Hi,
> >
> > You didn't say where you want the data pasting so this pastes ot ti row 1 in
> > the addded sheet. Alt+F11 to open VB editor. Right click 'This workbook' and
> > insert module and paste this code in and run it. It assumes your P&L data are
> > on sheet 1
> >
> > Sub Liminal()
> > lastrow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
> > Set myrange = Sheets("Sheet1").Range("A1:A" & lastrow)
> > For Each c In myrange
> > ShName = Left(c.Value, InStr(c.Value, " ") - 1)
> > Set c = c.Resize(, 20)
> > c.Copy
> > Worksheets.Add After:=ActiveSheet
> > ActiveSheet.Name = ShName
> > Range("A1").PasteSpecial
> > Next
> > End Sub
> >
> > Mike
> >
> > "sutha" wrote:
> >
> > > I HAVE A SHEET WITH P&L FOR 100 COMPANIES ONE BELOW ANOTHER. EACH P&L IS SAME
> > > IN SIZE( 20 RAWS)
> > >
> > > Can someone please help with a sub that will copy each p&l in different
> > > sheet and name each sheet with the 1st word found in the begining of the
> > > range (Eg; raw 1
> > > company name "xxx")

 
Reply With Quote
 
sutha
Guest
Posts: n/a
 
      5th Dec 2008
Hi ,
When I run the message popped up. there is no line number. Please bear with
me. I am new to VBa. Thanks


"Mike H" wrote:

> on which line?
>
> "sutha" wrote:
>
> > Hi Mike,
> > Thanks for your quick reply.i am geting an error message" invalid proceedure
> > call or argument'.
> > Sutha
> >
> > "Mike H" wrote:
> >
> > > Hi,
> > >
> > > You didn't say where you want the data pasting so this pastes ot ti row 1 in
> > > the addded sheet. Alt+F11 to open VB editor. Right click 'This workbook' and
> > > insert module and paste this code in and run it. It assumes your P&L data are
> > > on sheet 1
> > >
> > > Sub Liminal()
> > > lastrow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
> > > Set myrange = Sheets("Sheet1").Range("A1:A" & lastrow)
> > > For Each c In myrange
> > > ShName = Left(c.Value, InStr(c.Value, " ") - 1)
> > > Set c = c.Resize(, 20)
> > > c.Copy
> > > Worksheets.Add After:=ActiveSheet
> > > ActiveSheet.Name = ShName
> > > Range("A1").PasteSpecial
> > > Next
> > > End Sub
> > >
> > > Mike
> > >
> > > "sutha" wrote:
> > >
> > > > I HAVE A SHEET WITH P&L FOR 100 COMPANIES ONE BELOW ANOTHER. EACH P&L IS SAME
> > > > IN SIZE( 20 RAWS)
> > > >
> > > > Can someone please help with a sub that will copy each p&l in different
> > > > sheet and name each sheet with the 1st word found in the begining of the
> > > > range (Eg; raw 1
> > > > company name "xxx")

 
Reply With Quote
 
AndrewCerritos
Guest
Posts: n/a
 
      6th Dec 2008
Here is my take:
1) each company has exactly 20 rows of data
2) company name is the first word in first cell
3) active sheet is the original data of companies
4) the company worksheets are created at the end in order they appeared
5) the first company starts at the first non-blank row

Private Sub XfrCompPL()
Dim rngC1 As Range ' the range for Company
Dim nCol As Long ' number of columns
Dim strCName As String ' company name
Dim wsC1 As Worksheet ' target new worksheet name

nCol = ActiveSheet.UsedRange.Columns.Count
Set rngC1 = ActiveSheet.UsedRange.Range("A1") ' first cell
Do While rngC1.Value <> ""
strCName = Split(rngC1.Value, " ")(0) ' first word is company
name
Set rngC1 = rngC1.Resize(20, nCol) ' range is the company's
cells
Set wsC1 = Worksheets.Add(after:=Worksheets(Worksheets.Count)) '
last tab
wsC1.Name = strCName ' name the sheet
rngC1.Copy Destination:=wsC1.[A1] ' copy to it
Set rngC1 = rngC1.Range("A1").Offset(20) ' next company
Loop
End Sub

--AC

"Mike H" wrote:

> Hi,
>
> I just replicated that error on this like
>
> ShName = Left(c.Value, InStr(c.Value, " ") - 1)
>
> But the problem is on these 2 lines
>
> lastrow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
> Set myrange = Sheets("Sheet1").Range("A1:A" & lastrow)
>
> Change "Sheet1" on both these lines to the actual sheet name that contains
> your original data. Note the sheet name must be in quotes.
>
> In addition change "A" in both these lines to the first column of you P&L
> data, like wise the column leter must be in quotes.
>
> Mike
>
> "sutha" wrote:
>
> > Hi Mike,
> > Thanks for your quick reply.i am geting an error message" invalid proceedure
> > call or argument'.
> > Sutha
> >
> > "Mike H" wrote:
> >
> > > Hi,
> > >
> > > You didn't say where you want the data pasting so this pastes ot ti row 1 in
> > > the addded sheet. Alt+F11 to open VB editor. Right click 'This workbook' and
> > > insert module and paste this code in and run it. It assumes your P&L data are
> > > on sheet 1
> > >
> > > Sub Liminal()
> > > lastrow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
> > > Set myrange = Sheets("Sheet1").Range("A1:A" & lastrow)
> > > For Each c In myrange
> > > ShName = Left(c.Value, InStr(c.Value, " ") - 1)
> > > Set c = c.Resize(, 20)
> > > c.Copy
> > > Worksheets.Add After:=ActiveSheet
> > > ActiveSheet.Name = ShName
> > > Range("A1").PasteSpecial
> > > Next
> > > End Sub
> > >
> > > Mike
> > >
> > > "sutha" wrote:
> > >
> > > > I HAVE A SHEET WITH P&L FOR 100 COMPANIES ONE BELOW ANOTHER. EACH P&L IS SAME
> > > > IN SIZE( 20 RAWS)
> > > >
> > > > Can someone please help with a sub that will copy each p&l in different
> > > > sheet and name each sheet with the 1st word found in the begining of the
> > > > range (Eg; raw 1
> > > > company name "xxx")

 
Reply With Quote
 
sutha
Guest
Posts: n/a
 
      8th Dec 2008
Hi Andrew,
Works great for me. thanks a lot.

"AndrewCerritos" wrote:

> Here is my take:
> 1) each company has exactly 20 rows of data
> 2) company name is the first word in first cell
> 3) active sheet is the original data of companies
> 4) the company worksheets are created at the end in order they appeared
> 5) the first company starts at the first non-blank row
>
> Private Sub XfrCompPL()
> Dim rngC1 As Range ' the range for Company
> Dim nCol As Long ' number of columns
> Dim strCName As String ' company name
> Dim wsC1 As Worksheet ' target new worksheet name
>
> nCol = ActiveSheet.UsedRange.Columns.Count
> Set rngC1 = ActiveSheet.UsedRange.Range("A1") ' first cell
> Do While rngC1.Value <> ""
> strCName = Split(rngC1.Value, " ")(0) ' first word is company
> name
> Set rngC1 = rngC1.Resize(20, nCol) ' range is the company's
> cells
> Set wsC1 = Worksheets.Add(after:=Worksheets(Worksheets.Count)) '
> last tab
> wsC1.Name = strCName ' name the sheet
> rngC1.Copy Destination:=wsC1.[A1] ' copy to it
> Set rngC1 = rngC1.Range("A1").Offset(20) ' next company
> Loop
> End Sub
>
> --AC
>
> "Mike H" wrote:
>
> > Hi,
> >
> > I just replicated that error on this like
> >
> > ShName = Left(c.Value, InStr(c.Value, " ") - 1)
> >
> > But the problem is on these 2 lines
> >
> > lastrow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
> > Set myrange = Sheets("Sheet1").Range("A1:A" & lastrow)
> >
> > Change "Sheet1" on both these lines to the actual sheet name that contains
> > your original data. Note the sheet name must be in quotes.
> >
> > In addition change "A" in both these lines to the first column of you P&L
> > data, like wise the column leter must be in quotes.
> >
> > Mike
> >
> > "sutha" wrote:
> >
> > > Hi Mike,
> > > Thanks for your quick reply.i am geting an error message" invalid proceedure
> > > call or argument'.
> > > Sutha
> > >
> > > "Mike H" wrote:
> > >
> > > > Hi,
> > > >
> > > > You didn't say where you want the data pasting so this pastes ot ti row 1 in
> > > > the addded sheet. Alt+F11 to open VB editor. Right click 'This workbook' and
> > > > insert module and paste this code in and run it. It assumes your P&L data are
> > > > on sheet 1
> > > >
> > > > Sub Liminal()
> > > > lastrow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
> > > > Set myrange = Sheets("Sheet1").Range("A1:A" & lastrow)
> > > > For Each c In myrange
> > > > ShName = Left(c.Value, InStr(c.Value, " ") - 1)
> > > > Set c = c.Resize(, 20)
> > > > c.Copy
> > > > Worksheets.Add After:=ActiveSheet
> > > > ActiveSheet.Name = ShName
> > > > Range("A1").PasteSpecial
> > > > Next
> > > > End Sub
> > > >
> > > > Mike
> > > >
> > > > "sutha" wrote:
> > > >
> > > > > I HAVE A SHEET WITH P&L FOR 100 COMPANIES ONE BELOW ANOTHER. EACH P&L IS SAME
> > > > > IN SIZE( 20 RAWS)
> > > > >
> > > > > Can someone please help with a sub that will copy each p&l in different
> > > > > sheet and name each sheet with the 1st word found in the begining of the
> > > > > range (Eg; raw 1
> > > > > company name "xxx")

 
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
Re: Copy range on multiple sheets into one sheet Ron de Bruin Microsoft Excel Programming 3 30th May 2009 01:57 PM
Sheets named from range, and copy data? Jason.Alden.Benoit@gmail.com Microsoft Excel Misc 2 12th Jan 2007 02:53 PM
Copy Range and Paste to Array of Sheets bobwilson Microsoft Excel Programming 4 6th Apr 2006 01:23 PM
copy range between sheets chick-racer Microsoft Excel Programming 6 16th Dec 2003 05:50 PM
copy sheet1 and name sheets using names from a range DL Microsoft Excel Programming 2 2nd Sep 2003 12:58 PM


Features
 

Advertising
 

Newsgroups
 


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