PC Review


Reply
Thread Tools Rate Thread

Copy Section of One Worksheet to Multiple Worksheets

 
 
PHisaw
Guest
Posts: n/a
 
      15th Oct 2009
Hi,

I want to copy range v1:am75 from "Bookings" to the same section for sheets
"01-09", "02-09", "03-09", "04-09" and can get nothing to work.
Can someone please help with this?
Thanks in advance,
Phisaw
 
Reply With Quote
 
 
 
 
john
Guest
Posts: n/a
 
      15th Oct 2009
something like this may do what you want. Place in a standard module.

Sub CopyRanges()
Dim wsrng As Range
Dim myarray()

Set wsrng = Worksheets("Bookings").Range("V1:AM75")

myarray = Array("01-09", "02-09", "03-09", "04-09")

For i = LBound(myarray) To UBound(myarray)

Worksheets(myarray(i)).Range("V1:AM75").Value = wsrng.Value

Next

End Sub
--
jb


"PHisaw" wrote:

> Hi,
>
> I want to copy range v1:am75 from "Bookings" to the same section for sheets
> "01-09", "02-09", "03-09", "04-09" and can get nothing to work.
> Can someone please help with this?
> Thanks in advance,
> Phisaw

 
Reply With Quote
 
Per Jessen
Guest
Posts: n/a
 
      15th Oct 2009
Hi

See if this does what you need:

Sub aaa()
myArr = Split("01-09,02-09,03-09,04-09", ",")
Worksheets("Bookings").Range("V1:AM75").Copy
For sh = LBound(myArr) To UBound(myArr)
ActiveSheet.Paste Destination:=Worksheets(myArr(sh)).Range("V1")
Next
Application.CutCopyMode = False
End Sub

Regards,
Per

"PHisaw" <(E-Mail Removed)> skrev i meddelelsen
news:5FBC718E-EB19-4334-B9FC-(E-Mail Removed)...
> Hi,
>
> I want to copy range v1:am75 from "Bookings" to the same section for
> sheets
> "01-09", "02-09", "03-09", "04-09" and can get nothing to work.
> Can someone please help with this?
> Thanks in advance,
> Phisaw


 
Reply With Quote
 
PHisaw
Guest
Posts: n/a
 
      15th Oct 2009
John,

Thank you for replying. I tried the code and it caused an error "variable
not defined" on line

For i = LBound(myarray) To UBound(myarray) with "i" highlighted.

Can you please tell me how to define it? I'm a newbie and trying to learn.
Can you also please explain your code - LBound, UBound, etc.? Why wouldn't
something simple like the code below work?

Dim X As Variant
X = Array("01-09", "02-09", "03-09", _
"04-09", "05-09", "06-09")
Sheets(X).Copy _
Worksheets("Bookings").Range("v1:am75")

Thanks again,
Phisaw

"john" wrote:

> something like this may do what you want. Place in a standard module.
>
> Sub CopyRanges()
> Dim wsrng As Range
> Dim myarray()
>
> Set wsrng = Worksheets("Bookings").Range("V1:AM75")
>
> myarray = Array("01-09", "02-09", "03-09", "04-09")
>
> For i = LBound(myarray) To UBound(myarray)
>
> Worksheets(myarray(i)).Range("V1:AM75").Value = wsrng.Value
>
> Next
>
> End Sub
> --
> jb
>
>
> "PHisaw" wrote:
>
> > Hi,
> >
> > I want to copy range v1:am75 from "Bookings" to the same section for sheets
> > "01-09", "02-09", "03-09", "04-09" and can get nothing to work.
> > Can someone please help with this?
> > Thanks in advance,
> > Phisaw

 
Reply With Quote
 
PHisaw
Guest
Posts: n/a
 
      15th Oct 2009
John,

Thank you for replying. I tried the code and it caused an error "variable
not defined" on line:

For i = LBound(myarray) To UBound(myarray) with "i" highlighted.

Can you please tell me how to define it? I'm a newbie and trying to learn.
Can you also please explain your code - LBound, UBound, etc.? Why wouldn't
something simple like the code below work?

Dim X As Variant
X = Array("01-09", "02-09", "03-09", _
"04-09", "05-09", "06-09")
Sheets(X).Copy _
Worksheets("Bookings").Range("v1:am75")

Thanks again,
Phisaw

"john" wrote:

> something like this may do what you want. Place in a standard module.
>
> Sub CopyRanges()
> Dim wsrng As Range
> Dim myarray()
>
> Set wsrng = Worksheets("Bookings").Range("V1:AM75")
>
> myarray = Array("01-09", "02-09", "03-09", "04-09")
>
> For i = LBound(myarray) To UBound(myarray)
>
> Worksheets(myarray(i)).Range("V1:AM75").Value = wsrng.Value
>
> Next
>
> End Sub
> --
> jb
>
>
> "PHisaw" wrote:
>
> > Hi,
> >
> > I want to copy range v1:am75 from "Bookings" to the same section for sheets
> > "01-09", "02-09", "03-09", "04-09" and can get nothing to work.
> > Can someone please help with this?
> > Thanks in advance,
> > Phisaw

 
Reply With Quote
 
john
Guest
Posts: n/a
 
      15th Oct 2009
I omitted
Dim i As Integer

you could use copy if prefer but range should give required result.
--
jb


"PHisaw" wrote:

> John,
>
> Thank you for replying. I tried the code and it caused an error "variable
> not defined" on line:
>
> For i = LBound(myarray) To UBound(myarray) with "i" highlighted.
>
> Can you please tell me how to define it? I'm a newbie and trying to learn.
> Can you also please explain your code - LBound, UBound, etc.? Why wouldn't
> something simple like the code below work?
>
> Dim X As Variant
> X = Array("01-09", "02-09", "03-09", _
> "04-09", "05-09", "06-09")
> Sheets(X).Copy _
> Worksheets("Bookings").Range("v1:am75")
>
> Thanks again,
> Phisaw
>
> "john" wrote:
>
> > something like this may do what you want. Place in a standard module.
> >
> > Sub CopyRanges()
> > Dim wsrng As Range
> > Dim myarray()
> >
> > Set wsrng = Worksheets("Bookings").Range("V1:AM75")
> >
> > myarray = Array("01-09", "02-09", "03-09", "04-09")
> >
> > For i = LBound(myarray) To UBound(myarray)
> >
> > Worksheets(myarray(i)).Range("V1:AM75").Value = wsrng.Value
> >
> > Next
> >
> > End Sub
> > --
> > jb
> >
> >
> > "PHisaw" wrote:
> >
> > > Hi,
> > >
> > > I want to copy range v1:am75 from "Bookings" to the same section for sheets
> > > "01-09", "02-09", "03-09", "04-09" and can get nothing to work.
> > > Can someone please help with this?
> > > Thanks in advance,
> > > Phisaw

 
Reply With Quote
 
Patrick Molloy
Guest
Posts: n/a
 
      16th Oct 2009
dimensioning variables is good practice as it allows the compiler to allocate
the correct memory.
example

DIM i as Long

with arrays, they can be of indeterminite size
so for example you could could have X(1 to 10) or X(0 to y)
the functions UBOUND() and LBOUND() enable you find these boundaries

As yuo have it X is a variant containing strings(text) which are the names
of 6 worksheets
so
Sheets(X).Copy
is legitimate and wouild copy all 6 sheets to a new workbook
However, your target is a range, and you simply cannot copy 6 worksheets
into a range. sheets contain ranges, not vice-versa




"PHisaw" wrote:

> John,
>
> Thank you for replying. I tried the code and it caused an error "variable
> not defined" on line
>
> For i = LBound(myarray) To UBound(myarray) with "i" highlighted.
>
> Can you please tell me how to define it? I'm a newbie and trying to learn.
> Can you also please explain your code - LBound, UBound, etc.? Why wouldn't
> something simple like the code below work?
>
> Dim X As Variant
> X = Array("01-09", "02-09", "03-09", _
> "04-09", "05-09", "06-09")
> Sheets(X).Copy _
> Worksheets("Bookings").Range("v1:am75")
>
> Thanks again,
> Phisaw
>
> "john" wrote:
>
> > something like this may do what you want. Place in a standard module.
> >
> > Sub CopyRanges()
> > Dim wsrng As Range
> > Dim myarray()
> >
> > Set wsrng = Worksheets("Bookings").Range("V1:AM75")
> >
> > myarray = Array("01-09", "02-09", "03-09", "04-09")
> >
> > For i = LBound(myarray) To UBound(myarray)
> >
> > Worksheets(myarray(i)).Range("V1:AM75").Value = wsrng.Value
> >
> > Next
> >
> > End Sub
> > --
> > jb
> >
> >
> > "PHisaw" wrote:
> >
> > > Hi,
> > >
> > > I want to copy range v1:am75 from "Bookings" to the same section for sheets
> > > "01-09", "02-09", "03-09", "04-09" and can get nothing to work.
> > > Can someone please help with this?
> > > Thanks in advance,
> > > Phisaw

 
Reply With Quote
 
PHisaw
Guest
Posts: n/a
 
      16th Oct 2009
Thank you both, John and Patrick, for the code and explanation. Greatly
appreciated.

"Patrick Molloy" wrote:

> dimensioning variables is good practice as it allows the compiler to allocate
> the correct memory.
> example
>
> DIM i as Long
>
> with arrays, they can be of indeterminite size
> so for example you could could have X(1 to 10) or X(0 to y)
> the functions UBOUND() and LBOUND() enable you find these boundaries
>
> As yuo have it X is a variant containing strings(text) which are the names
> of 6 worksheets
> so
> Sheets(X).Copy
> is legitimate and wouild copy all 6 sheets to a new workbook
> However, your target is a range, and you simply cannot copy 6 worksheets
> into a range. sheets contain ranges, not vice-versa
>
>
>
>
> "PHisaw" wrote:
>
> > John,
> >
> > Thank you for replying. I tried the code and it caused an error "variable
> > not defined" on line
> >
> > For i = LBound(myarray) To UBound(myarray) with "i" highlighted.
> >
> > Can you please tell me how to define it? I'm a newbie and trying to learn.
> > Can you also please explain your code - LBound, UBound, etc.? Why wouldn't
> > something simple like the code below work?
> >
> > Dim X As Variant
> > X = Array("01-09", "02-09", "03-09", _
> > "04-09", "05-09", "06-09")
> > Sheets(X).Copy _
> > Worksheets("Bookings").Range("v1:am75")
> >
> > Thanks again,
> > Phisaw
> >
> > "john" wrote:
> >
> > > something like this may do what you want. Place in a standard module.
> > >
> > > Sub CopyRanges()
> > > Dim wsrng As Range
> > > Dim myarray()
> > >
> > > Set wsrng = Worksheets("Bookings").Range("V1:AM75")
> > >
> > > myarray = Array("01-09", "02-09", "03-09", "04-09")
> > >
> > > For i = LBound(myarray) To UBound(myarray)
> > >
> > > Worksheets(myarray(i)).Range("V1:AM75").Value = wsrng.Value
> > >
> > > Next
> > >
> > > End Sub
> > > --
> > > jb
> > >
> > >
> > > "PHisaw" wrote:
> > >
> > > > Hi,
> > > >
> > > > I want to copy range v1:am75 from "Bookings" to the same section for sheets
> > > > "01-09", "02-09", "03-09", "04-09" and can get nothing to work.
> > > > Can someone please help with this?
> > > > Thanks in advance,
> > > > Phisaw

 
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 same cell in multiple worksheets onto one worksheet Tia Microsoft Excel Misc 1 17th Sep 2009 12:40 AM
How to copy worksheet template into multiple worksheets Nelson Microsoft Excel Programming 1 10th Jun 2009 11:21 PM
how to copy data from one worksheet to multiple worksheets at once zeb Microsoft Excel Worksheet Functions 2 21st Oct 2008 07:25 PM
Copy range from one worksheet and paste to multiple worksheets mooring Microsoft Excel Misc 10 19th Jan 2008 04:19 PM
Copy Range From Multiple Worksheets to a Single Worksheet Dauntless1 Microsoft Excel Misc 5 17th Aug 2007 01:59 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:48 PM.