Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 183
Default vba for selecting multiple sheets to save as a new book

I searched through postings but couldn't find one which I could comprehend to
address this issue.

Earlier today, your support corrected my code in order to copy&save a single
sheet to a new workbook. :) thankyou!

Now I have several sheets from the book (over 50 sheets within the book)
that we want to copy to a new book.

Once again I tried to record the macro, then edit...but I receive a "compile
error Sub or Function not defined"

The following are the different ways we tried ;
Compile errors:
Selection([Sheet4], [Sheet5], [Sheet6]).Activate
Worksheets(Array(Sheet4, Sheet5, Sheet6)).Activate
Wrong set of Argument errors:
Selection(Sheet4, Sheet5, Sheet6).Activate
Sheets(Sheet4, Sheet5, Sheet6).Activate






  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default vba for selecting multiple sheets to save as a new book

How about treating those names as text and putting them in double quotes:

Worksheets(Array("sheet4", "Sheet5", "Sheet6")).select
(not .activate)

If I were you, I'd drop the use of []'s.



Sharon wrote:

I searched through postings but couldn't find one which I could comprehend to
address this issue.

Earlier today, your support corrected my code in order to copy&save a single
sheet to a new workbook. :) thankyou!

Now I have several sheets from the book (over 50 sheets within the book)
that we want to copy to a new book.

Once again I tried to record the macro, then edit...but I receive a "compile
error Sub or Function not defined"

The following are the different ways we tried ;
Compile errors:
Selection([Sheet4], [Sheet5], [Sheet6]).Activate
Worksheets(Array(Sheet4, Sheet5, Sheet6)).Activate
Wrong set of Argument errors:
Selection(Sheet4, Sheet5, Sheet6).Activate
Sheets(Sheet4, Sheet5, Sheet6).Activate


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 183
Default vba for selecting multiple sheets to save as a new book

The tabs actually have text names, sheet4-6 refer to the sheet name when
viewing the sheet in the vba editor. I wanted to use that in case we change
a tab's name in the worksheet.

I've tried your suggestion both in & without quotes,however, debug advises a
"Type mismatch (Error 13)



"Dave Peterson" wrote:

How about treating those names as text and putting them in double quotes:

Worksheets(Array("sheet4", "Sheet5", "Sheet6")).select
(not .activate)

If I were you, I'd drop the use of []'s.



Sharon wrote:

I searched through postings but couldn't find one which I could comprehend to
address this issue.

Earlier today, your support corrected my code in order to copy&save a single
sheet to a new workbook. :) thankyou!

Now I have several sheets from the book (over 50 sheets within the book)
that we want to copy to a new book.

Once again I tried to record the macro, then edit...but I receive a "compile
error Sub or Function not defined"

The following are the different ways we tried ;
Compile errors:
Selection([Sheet4], [Sheet5], [Sheet6]).Activate
Worksheets(Array(Sheet4, Sheet5, Sheet6)).Activate
Wrong set of Argument errors:
Selection(Sheet4, Sheet5, Sheet6).Activate
Sheets(Sheet4, Sheet5, Sheet6).Activate


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 183
Default vba for selecting multiple sheets to save as a new book

After playing around some more, I found the following syntax works. Thanks
for your time!

Sheets(Array(4, 5, 6)).Select
Sheets(Array(4, 5, 6)).Copy


"Sharon" wrote:

The tabs actually have text names, sheet4-6 refer to the sheet name when
viewing the sheet in the vba editor. I wanted to use that in case we change
a tab's name in the worksheet.

I've tried your suggestion both in & without quotes,however, debug advises a
"Type mismatch (Error 13)



"Dave Peterson" wrote:

How about treating those names as text and putting them in double quotes:

Worksheets(Array("sheet4", "Sheet5", "Sheet6")).select
(not .activate)

If I were you, I'd drop the use of []'s.



Sharon wrote:

I searched through postings but couldn't find one which I could comprehend to
address this issue.

Earlier today, your support corrected my code in order to copy&save a single
sheet to a new workbook. :) thankyou!

Now I have several sheets from the book (over 50 sheets within the book)
that we want to copy to a new book.

Once again I tried to record the macro, then edit...but I receive a "compile
error Sub or Function not defined"

The following are the different ways we tried ;
Compile errors:
Selection([Sheet4], [Sheet5], [Sheet6]).Activate
Worksheets(Array(Sheet4, Sheet5, Sheet6)).Activate
Wrong set of Argument errors:
Selection(Sheet4, Sheet5, Sheet6).Activate
Sheets(Sheet4, Sheet5, Sheet6).Activate


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default vba for selecting multiple sheets to save as a new book

If you're afraid of worksheet names changing, aren't you concerned that the
sheets will be moved (left or right)???

Maybe using the codenames to get the sheet names would be safer.

Option Explicit
Sub testme02()

Dim myCodeNames As Variant
Dim iCtr As Long
Dim mySheetNames() As String
Dim mySht As Object
Dim res As Variant

With ActiveWorkbook

myCodeNames = Array("Sheet1", "sheet3", "Sheet5")
ReDim mySheetNames(1 To .Sheets.Count)

iCtr = 0
For Each mySht In .Sheets
res = Application.Match(mySht.CodeName, myCodeNames, 0)
If IsError(res) Then
'no match, the board goes back
Else
iCtr = iCtr + 1
mySheetNames(iCtr) = mySht.Name
End If
Next mySht

If iCtr = 0 Then
MsgBox "no sheets to copy!"
Else
If UBound(myCodeNames) - LBound(myCodeNames) + 1 < iCtr Then
MsgBox "Not all sheets found"
Else
ReDim Preserve mySheetNames(1 To iCtr)
.Sheets(mySheetNames).Copy 'to a new workbook?
End If
End If
End With

End Sub


Sharon wrote:

After playing around some more, I found the following syntax works. Thanks
for your time!

Sheets(Array(4, 5, 6)).Select
Sheets(Array(4, 5, 6)).Copy

"Sharon" wrote:

The tabs actually have text names, sheet4-6 refer to the sheet name when
viewing the sheet in the vba editor. I wanted to use that in case we change
a tab's name in the worksheet.

I've tried your suggestion both in & without quotes,however, debug advises a
"Type mismatch (Error 13)



"Dave Peterson" wrote:

How about treating those names as text and putting them in double quotes:

Worksheets(Array("sheet4", "Sheet5", "Sheet6")).select
(not .activate)

If I were you, I'd drop the use of []'s.



Sharon wrote:

I searched through postings but couldn't find one which I could comprehend to
address this issue.

Earlier today, your support corrected my code in order to copy&save a single
sheet to a new workbook. :) thankyou!

Now I have several sheets from the book (over 50 sheets within the book)
that we want to copy to a new book.

Once again I tried to record the macro, then edit...but I receive a "compile
error Sub or Function not defined"

The following are the different ways we tried ;
Compile errors:
Selection([Sheet4], [Sheet5], [Sheet6]).Activate
Worksheets(Array(Sheet4, Sheet5, Sheet6)).Activate
Wrong set of Argument errors:
Selection(Sheet4, Sheet5, Sheet6).Activate
Sheets(Sheet4, Sheet5, Sheet6).Activate

--

Dave Peterson


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 183
Default vba for selecting multiple sheets to save as a new book

THANKYOU Once Again!! works like a charm. Maybe someday I'll actually
understand it :)


"Dave Peterson" wrote:

If you're afraid of worksheet names changing, aren't you concerned that the
sheets will be moved (left or right)???

Maybe using the codenames to get the sheet names would be safer.

Option Explicit
Sub testme02()

Dim myCodeNames As Variant
Dim iCtr As Long
Dim mySheetNames() As String
Dim mySht As Object
Dim res As Variant

With ActiveWorkbook

myCodeNames = Array("Sheet1", "sheet3", "Sheet5")
ReDim mySheetNames(1 To .Sheets.Count)

iCtr = 0
For Each mySht In .Sheets
res = Application.Match(mySht.CodeName, myCodeNames, 0)
If IsError(res) Then
'no match, the board goes back
Else
iCtr = iCtr + 1
mySheetNames(iCtr) = mySht.Name
End If
Next mySht

If iCtr = 0 Then
MsgBox "no sheets to copy!"
Else
If UBound(myCodeNames) - LBound(myCodeNames) + 1 < iCtr Then
MsgBox "Not all sheets found"
Else
ReDim Preserve mySheetNames(1 To iCtr)
.Sheets(mySheetNames).Copy 'to a new workbook?
End If
End If
End With

End Sub


Sharon wrote:

After playing around some more, I found the following syntax works. Thanks
for your time!

Sheets(Array(4, 5, 6)).Select
Sheets(Array(4, 5, 6)).Copy

"Sharon" wrote:

The tabs actually have text names, sheet4-6 refer to the sheet name when
viewing the sheet in the vba editor. I wanted to use that in case we change
a tab's name in the worksheet.

I've tried your suggestion both in & without quotes,however, debug advises a
"Type mismatch (Error 13)



"Dave Peterson" wrote:

How about treating those names as text and putting them in double quotes:

Worksheets(Array("sheet4", "Sheet5", "Sheet6")).select
(not .activate)

If I were you, I'd drop the use of []'s.



Sharon wrote:

I searched through postings but couldn't find one which I could comprehend to
address this issue.

Earlier today, your support corrected my code in order to copy&save a single
sheet to a new workbook. :) thankyou!

Now I have several sheets from the book (over 50 sheets within the book)
that we want to copy to a new book.

Once again I tried to record the macro, then edit...but I receive a "compile
error Sub or Function not defined"

The following are the different ways we tried ;
Compile errors:
Selection([Sheet4], [Sheet5], [Sheet6]).Activate
Worksheets(Array(Sheet4, Sheet5, Sheet6)).Activate
Wrong set of Argument errors:
Selection(Sheet4, Sheet5, Sheet6).Activate
Sheets(Sheet4, Sheet5, Sheet6).Activate

--

Dave Peterson


--

Dave Peterson

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
Loading Data into Multiple sheets in 1 book [email protected] New Users to Excel 1 September 10th 06 03:41 PM
Loading Data into Multiple sheets in 1 book [email protected] Setting up and Configuration of Excel 0 September 7th 06 03:41 PM
Loading Data into Multiple sheets in 1 book [email protected] Excel Discussion (Misc queries) 0 September 7th 06 03:34 PM
Selecting Multiple Sheets in VBA Gizmo63 Excel Worksheet Functions 4 May 8th 06 01:50 PM
selecting multiple sheets Shaun Excel Worksheet Functions 1 August 31st 05 04:09 PM


All times are GMT +1. The time now is 07:00 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"