PC Review


Reply
Thread Tools Rate Thread

Copy fixed range of multiple sheets into new workbook

 
 
A. Karatas
Guest
Posts: n/a
 
      11th Jun 2007
I have a workbook with multiple sheets in them. I want to copy a
particular fixed range of each sheet, in which the sheetname ends on
PY) into a new workbook. For example sheetname= Emuls(actual vs PY)
range b4:s40.

Each range has to be copied into a (seperate) new sheet with the
sheetname it had on the original workbook.

I have no clou how to start the procedure????

thankx in advance

 
Reply With Quote
 
 
 
 
Norman Jones
Guest
Posts: n/a
 
      11th Jun 2007
Hi A,

Try something like:

Public Sub aTester001()
Dim srcWB As Workbook
Dim destWB As Workbook
Dim SH As Worksheet
Dim destSH As Worksheet
Dim srcRng As Range
Dim blOK As Boolean
Const sStr As String = "PY" '<<=== CHANGE

Set srcWB = Workbooks("MyBokk.xls") '<<=== CHANGE

blOK = True
For Each SH In srcWB.Worksheets
If UCase(SH.Name) Like UCase("*" & sStr) Then
If blOK Then
Set destWB = Workbooks.Add
End If
blOK = False
With destWB
Set destSH = .Sheets.Add( _
After:=.Sheets(.Sheets.Count))
End With
With destSH
.Name = SH.Name
SH.Range("B4:S40").Copy Destination:=.Range("A1")
End With
End If
Next SH

End Sub
'<<=============


---
Regards,
Norman


"A. Karatas" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have a workbook with multiple sheets in them. I want to copy a
> particular fixed range of each sheet, in which the sheetname ends on
> PY) into a new workbook. For example sheetname= Emuls(actual vs PY)
> range b4:s40.
>
> Each range has to be copied into a (seperate) new sheet with the
> sheetname it had on the original workbook.
>
> I have no clou how to start the procedure????
>
> thankx in advance
>



 
Reply With Quote
 
A. Karatas
Guest
Posts: n/a
 
      11th Jun 2007
Hi Norman,

It works great, but what if I want the copied figures to be in "paste
special" format and values???

 
Reply With Quote
 
A. Karatas
Guest
Posts: n/a
 
      11th Jun 2007
Hi Norman,

It works great, but what if I want the copied sheets to be in "paste
special" format and values???

Also the workbookname changes each month. Is there a way of
incorporating a procedure in which the target workbook is defined
like:
Dim TargetWB As Workbook
Set TargetWB = ActiveWorkbook


Thankx


 
Reply With Quote
 
Norman Jones
Guest
Posts: n/a
 
      11th Jun 2007
Hi A,

Try something like:

'<<=============
Public Sub aTester()
Dim srcWB As Workbook
Dim destWB As Workbook
Dim SH As Worksheet
Dim destSH As Worksheet
Dim srcRng As Range
Const sStr As String = "PY" '<<=== CHANGE

Set srcWB = Workbooks("MyBook.xls") '<<=== CHANGE
Set destWB = ActiveWorkbook

For Each SH In srcWB.Worksheets
If UCase(SH.Name) Like UCase("*" & sStr) Then
With destWB
Set destSH = .Sheets.Add( _
After:=.Sheets(.Sheets.Count))
End With
destSH.Name = SH.Name
With SH.Range("B4:S40")
destSH.Range("A1").Resize(.Rows.Count, _
.Columns.Count).Value = .Value
End With

End If
Next SH
End Sub
'<<=============


---
Regards,
Norman


"A. Karatas" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Norman,
>
> It works great, but what if I want the copied sheets to be in "paste
> special" format and values???
>
> Also the workbookname changes each month. Is there a way of
> incorporating a procedure in which the target workbook is defined
> like:
> Dim TargetWB As Workbook
> Set TargetWB = ActiveWorkbook
>
>
> Thankx
>
>



 
Reply With Quote
 
A. Karatas
Guest
Posts: n/a
 
      12th Jun 2007
Hi Norman

The line ' destSH.Name = SH.Name ' gives an error.

Cannot rename a sheet to the same name as another sheet, a referenced
object library or a workbook referenced by visual basic.


 
Reply With Quote
 
A. Karatas
Guest
Posts: n/a
 
      12th Jun 2007
Hi

The line ' destSH.Name = SH.Name ' gives an error.


Cannot rename a sheet to the same name as another sheet, a referenced
object library or a workbook referenced by visual basic.

It looks like the destination of the sheets is in the mastersheet
itself



 
Reply With Quote
 
Norman Jones
Guest
Posts: n/a
 
      12th Jun 2007
Hi A,

The code works for me without problem.

I could, however, reproduce your error if I
inadvertently trised to re-run the procedure;
that is not surprising as it is not possible to
create 2 sets of identically named sheets in the
same workbook.

BTW, srcWb should be the workbook which
contains the sheets to be copied; destWb should
be the active workbook (in accordance with your
request) and is the workbook which should receive
the copied sheets.


---
Regards,
Norman

"A. Karatas" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Norman
>
> The line ' destSH.Name = SH.Name ' gives an error.
>
> Cannot rename a sheet to the same name as another sheet, a referenced
> object library or a workbook referenced by visual basic.
>
>



 
Reply With Quote
 
Norman Jones
Guest
Posts: n/a
 
      12th Jun 2007
Hi A,

See my immediately preceding response.


---
Regards,
Norman

"A. Karatas" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi
>
> The line ' destSH.Name = SH.Name ' gives an error.
>
>
> Cannot rename a sheet to the same name as another sheet, a referenced
> object library or a workbook referenced by visual basic.
>
> It looks like the destination of the sheets is in the mastersheet
> itself
>
>
>


 
Reply With Quote
 
A. Karatas
Guest
Posts: n/a
 
      12th Jun 2007
Norman,

The first macro you wrote, works perfectly each time. It copies the
sheets and puts it in the destWB. The second still gives an error and
in my opinion tries to put the copied sheets into the srcWB

Perhaps it's an idea to work out the first macro in which the sheets
are copied in fixed value and format.

I know I maybe asking much, but as I am not that familiar with VB,
your a hope for me

thankx

 
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 chart between multiple sheets in workbook Sam Microsoft Excel Charting 4 12th Mar 2010 03:59 PM
Copy cell (C6) from multiple sheets in a wbook to another workbook nasir.gami@gmail.com Microsoft Excel Programming 2 9th Feb 2007 10:28 PM
Copy cell (C6) from multiple sheets in a wbook to another workbook nasir.gami@gmail.com Microsoft Excel Programming 0 9th Feb 2007 03:30 PM
Copy cell (C6) from multiple sheets in a wbook to another workbook nasir.gami@gmail.com Microsoft Excel Programming 0 9th Feb 2007 03:30 PM
Copy cell (C6) from multiple sheets in a wbook to another workbook nasir.gami@gmail.com Microsoft Excel Programming 0 9th Feb 2007 03:30 PM


Features
 

Advertising
 

Newsgroups
 


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