Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Select and copy certain tabs using macro

I am working with a workbook in Excel 2003 that has over 40 tabs
(worksheets). Each worksheet is a department report and each department has 4
reports. The last report is the one I need to select for each department and
copy it into a new workbook. The name of the worksheets to be selected copied
and pasted is "xxxxx-RSS Upload" where x is the department number. I was
trying to find a property that could only select the "Upload" part of the
worksheet name as a common denominator to select multiple worksheets that end
with that text string. I started of like this:

Sub Macro3()
Dim ws As Worksheet
For Each ws In Worksheets
If UCase(Right(Trim(ws.Name), 6)) = "UPLOAD" Then
ws.Select
ws.Copy After:=Workbooks("newbook"). _
Worksheets(Workbooks("newbook").Worksheets.Count)
End If
Next ws

End Sub

The Macro stops and gets error '9': Subscript out of range

The debugger directs me to the following line:
ws.Copy After:=Workbooks("newbook"). _
Worksheets(Workbooks("newbook").Worksheets.Count)

If I remove this line the Macro works fine selecting only the tabs i want,
so I know I am halfway in the right direction. Can anybody come up with a
solution for this??? Thanks in advance for your help



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Select and copy certain tabs using macro

I had already tried that. Thanks.

"Don Guillett" wrote:

WithOUT testing how about newbook.xls

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"FLORERO" wrote in message
...
I am working with a workbook in Excel 2003 that has over 40 tabs
(worksheets). Each worksheet is a department report and each department
has 4
reports. The last report is the one I need to select for each department
and
copy it into a new workbook. The name of the worksheets to be selected
copied
and pasted is "xxxxx-RSS Upload" where x is the department number. I was
trying to find a property that could only select the "Upload" part of the
worksheet name as a common denominator to select multiple worksheets that
end
with that text string. I started of like this:

Sub Macro3()
Dim ws As Worksheet
For Each ws In Worksheets
If UCase(Right(Trim(ws.Name), 6)) = "UPLOAD" Then
ws.Select
ws.Copy After:=Workbooks("newbook"). _
Worksheets(Workbooks("newbook").Worksheets.Count)
End If
Next ws

End Sub

The Macro stops and gets error '9': Subscript out of range

The debugger directs me to the following line:
ws.Copy After:=Workbooks("newbook"). _
Worksheets(Workbooks("newbook").Worksheets.Count)

If I remove this line the Macro works fine selecting only the tabs i want,
so I know I am halfway in the right direction. Can anybody come up with a
solution for this??? Thanks in advance for your help





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Select and copy certain tabs using macro

Try creating the new workbook firstname itthen copy sheets to it
or this may be quicker
delete all sheets not containing the text and then saveAS something else.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"FLORERO" wrote in message
...
I had already tried that. Thanks.

"Don Guillett" wrote:

WithOUT testing how about newbook.xls

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"FLORERO" wrote in message
...
I am working with a workbook in Excel 2003 that has over 40 tabs
(worksheets). Each worksheet is a department report and each department
has 4
reports. The last report is the one I need to select for each
department
and
copy it into a new workbook. The name of the worksheets to be selected
copied
and pasted is "xxxxx-RSS Upload" where x is the department number. I
was
trying to find a property that could only select the "Upload" part of
the
worksheet name as a common denominator to select multiple worksheets
that
end
with that text string. I started of like this:

Sub Macro3()
Dim ws As Worksheet
For Each ws In Worksheets
If UCase(Right(Trim(ws.Name), 6)) = "UPLOAD" Then
ws.Select
ws.Copy After:=Workbooks("newbook"). _
Worksheets(Workbooks("newbook").Worksheets.Count)
End If
Next ws

End Sub

The Macro stops and gets error '9': Subscript out of range

The debugger directs me to the following line:
ws.Copy After:=Workbooks("newbook"). _
Worksheets(Workbooks("newbook").Worksheets.Count)

If I remove this line the Macro works fine selecting only the tabs i
want,
so I know I am halfway in the right direction. Can anybody come up with
a
solution for this??? Thanks in advance for your help






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Select and copy certain tabs using macro

Try this idea instead
=SUM(U7:OFFSET(U7,0,d3-1))

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"FLORERO" wrote in message
...
I had already tried that. Thanks.

"Don Guillett" wrote:

WithOUT testing how about newbook.xls

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"FLORERO" wrote in message
...
I am working with a workbook in Excel 2003 that has over 40 tabs
(worksheets). Each worksheet is a department report and each department
has 4
reports. The last report is the one I need to select for each
department
and
copy it into a new workbook. The name of the worksheets to be selected
copied
and pasted is "xxxxx-RSS Upload" where x is the department number. I
was
trying to find a property that could only select the "Upload" part of
the
worksheet name as a common denominator to select multiple worksheets
that
end
with that text string. I started of like this:

Sub Macro3()
Dim ws As Worksheet
For Each ws In Worksheets
If UCase(Right(Trim(ws.Name), 6)) = "UPLOAD" Then
ws.Select
ws.Copy After:=Workbooks("newbook"). _
Worksheets(Workbooks("newbook").Worksheets.Count)
End If
Next ws

End Sub

The Macro stops and gets error '9': Subscript out of range

The debugger directs me to the following line:
ws.Copy After:=Workbooks("newbook"). _
Worksheets(Workbooks("newbook").Worksheets.Count)

If I remove this line the Macro works fine selecting only the tabs i
want,
so I know I am halfway in the right direction. Can anybody come up with
a
solution for this??? Thanks in advance for your help








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Select and copy certain tabs using macro

changed your code abit but this seemed to work but assumes NewBook exists and
is open:

Sub Macro()
Dim ws As Worksheet
Dim Dwb As Workbook
Dim Awb As Workbook

Set Awb = ActiveWorkbook
Set Dwb = Workbooks("NewBook")
Application.ScreenUpdating = False
cws = Dwb.Worksheets.Count
For Each ws In Worksheets
If UCase(Right(Trim(ws.Name), 6)) = "UPLOAD" Then
ws.Select
ws.Copy After:=Workbooks("NewBook").Worksheets(cws)
End If
Awb.Activate
Next ws
Application.ScreenUpdating = True
End Sub
--
JB


"FLORERO" wrote:

I am working with a workbook in Excel 2003 that has over 40 tabs
(worksheets). Each worksheet is a department report and each department has 4
reports. The last report is the one I need to select for each department and
copy it into a new workbook. The name of the worksheets to be selected copied
and pasted is "xxxxx-RSS Upload" where x is the department number. I was
trying to find a property that could only select the "Upload" part of the
worksheet name as a common denominator to select multiple worksheets that end
with that text string. I started of like this:

Sub Macro3()
Dim ws As Worksheet
For Each ws In Worksheets
If UCase(Right(Trim(ws.Name), 6)) = "UPLOAD" Then
ws.Select
ws.Copy After:=Workbooks("newbook"). _
Worksheets(Workbooks("newbook").Worksheets.Count)
End If
Next ws

End Sub

The Macro stops and gets error '9': Subscript out of range

The debugger directs me to the following line:
ws.Copy After:=Workbooks("newbook"). _
Worksheets(Workbooks("newbook").Worksheets.Count)

If I remove this line the Macro works fine selecting only the tabs i want,
so I know I am halfway in the right direction. Can anybody come up with a
solution for this??? Thanks in advance for your help



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Select and copy certain tabs using macro

Thank you very much John it worked

"john" wrote:

changed your code abit but this seemed to work but assumes NewBook exists and
is open:

Sub Macro()
Dim ws As Worksheet
Dim Dwb As Workbook
Dim Awb As Workbook

Set Awb = ActiveWorkbook
Set Dwb = Workbooks("NewBook")
Application.ScreenUpdating = False
cws = Dwb.Worksheets.Count
For Each ws In Worksheets
If UCase(Right(Trim(ws.Name), 6)) = "UPLOAD" Then
ws.Select
ws.Copy After:=Workbooks("NewBook").Worksheets(cws)
End If
Awb.Activate
Next ws
Application.ScreenUpdating = True
End Sub
--
JB


"FLORERO" wrote:

I am working with a workbook in Excel 2003 that has over 40 tabs
(worksheets). Each worksheet is a department report and each department has 4
reports. The last report is the one I need to select for each department and
copy it into a new workbook. The name of the worksheets to be selected copied
and pasted is "xxxxx-RSS Upload" where x is the department number. I was
trying to find a property that could only select the "Upload" part of the
worksheet name as a common denominator to select multiple worksheets that end
with that text string. I started of like this:

Sub Macro3()
Dim ws As Worksheet
For Each ws In Worksheets
If UCase(Right(Trim(ws.Name), 6)) = "UPLOAD" Then
ws.Select
ws.Copy After:=Workbooks("newbook"). _
Worksheets(Workbooks("newbook").Worksheets.Count)
End If
Next ws

End Sub

The Macro stops and gets error '9': Subscript out of range

The debugger directs me to the following line:
ws.Copy After:=Workbooks("newbook"). _
Worksheets(Workbooks("newbook").Worksheets.Count)

If I remove this line the Macro works fine selecting only the tabs i want,
so I know I am halfway in the right direction. Can anybody come up with a
solution for this??? Thanks in advance for your help



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Select and copy certain tabs using macro

Glad to be of help. If you want to create a New workbook programmatically you
could try following: (untested)

Sub Macro()
Dim ws As Worksheet
Dim Dwb As Workbook
Dim Awb As Workbook

Application.ScreenUpdating = False

Set Awb = ThisWorkbook
Set Dwb = Workbooks.Add
Dwb.SaveAs "C:\NewBook"

For Each ws In Awb.Worksheets
If UCase(Right(Trim(ws.Name), 6)) = "UPLOAD" Then
ws.Copy After:=Workbooks(Dwb.Name).Worksheets _
(Workbooks(Dwb.Name).Worksheets.Count)
End If
Awb.Activate
Next ws
Application.ScreenUpdating = True
End Sub
--
JB


"FLORERO" wrote:

Thank you very much John it worked

"john" wrote:

changed your code abit but this seemed to work but assumes NewBook exists and
is open:

Sub Macro()
Dim ws As Worksheet
Dim Dwb As Workbook
Dim Awb As Workbook

Set Awb = ActiveWorkbook
Set Dwb = Workbooks("NewBook")
Application.ScreenUpdating = False
cws = Dwb.Worksheets.Count
For Each ws In Worksheets
If UCase(Right(Trim(ws.Name), 6)) = "UPLOAD" Then
ws.Select
ws.Copy After:=Workbooks("NewBook").Worksheets(cws)
End If
Awb.Activate
Next ws
Application.ScreenUpdating = True
End Sub
--
JB


"FLORERO" wrote:

I am working with a workbook in Excel 2003 that has over 40 tabs
(worksheets). Each worksheet is a department report and each department has 4
reports. The last report is the one I need to select for each department and
copy it into a new workbook. The name of the worksheets to be selected copied
and pasted is "xxxxx-RSS Upload" where x is the department number. I was
trying to find a property that could only select the "Upload" part of the
worksheet name as a common denominator to select multiple worksheets that end
with that text string. I started of like this:

Sub Macro3()
Dim ws As Worksheet
For Each ws In Worksheets
If UCase(Right(Trim(ws.Name), 6)) = "UPLOAD" Then
ws.Select
ws.Copy After:=Workbooks("newbook"). _
Worksheets(Workbooks("newbook").Worksheets.Count)
End If
Next ws

End Sub

The Macro stops and gets error '9': Subscript out of range

The debugger directs me to the following line:
ws.Copy After:=Workbooks("newbook"). _
Worksheets(Workbooks("newbook").Worksheets.Count)

If I remove this line the Macro works fine selecting only the tabs i want,
so I know I am halfway in the right direction. Can anybody come up with a
solution for this??? Thanks in advance for your help



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Select certain tabs using macro FLORERO Excel Programming 5 November 28th 07 10:29 PM
Macro - Copy row and paste on all tabs masterbaker Excel Programming 4 July 12th 07 01:45 PM
Macro: search word, select row, copy. Raul[_2_] Excel Programming 3 June 21st 07 04:51 PM
Macro to copy hidden sheet to front of tabs? StargateFan[_3_] Excel Programming 1 October 20th 05 01:47 PM
Select/Copy/Paste in Macro/VBA Jim Clark Excel Programming 1 September 1st 04 09:34 AM


All times are GMT +1. The time now is 02:33 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"