Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 425
Default Group sheets using code

I have several macros that I need to record where I group sheets, then
perform the actions.
I need a code that will group sheets by sheetname range (i.e. "apples"
to "oranges").
I will record myself perfoming the various actions to get the code to
finish it, however, I need a general/ basic grouping code to start off.



Thanx.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Group sheets using code

The select method for worksheets has an option argument Replace (true by
Default) which specifies whether you want to group the sheet you are
selecting with the already selected sheet(s). By setting the value to false
you can group...

Sheets("Sheet1").Select False
Sheets("Sheet2").Select False
Sheets("Sheet3").Select False

--
HTH...

Jim Thomlinson


"J.W. Aldridge" wrote:

I have several macros that I need to record where I group sheets, then
perform the actions.
I need a code that will group sheets by sheetname range (i.e. "apples"
to "oranges").
I will record myself perfoming the various actions to get the code to
finish it, however, I need a general/ basic grouping code to start off.



Thanx.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Group sheets using code

Function GroupSheets(StartSheet As String, EndSheet As String)
Dim iStart As Long
Dim iEnd As Long
Dim i As Long, j As Long
Dim arySheets

On Error Resume Next
iStart = ActiveWorkbook.Worksheets(StartSheet).Index
iEnd = ActiveWorkbook.Worksheets(EndSheet).Index
On Error GoTo 0
If iStart = 0 Or iEnd = 0 Or iEnd < iStart Then
MsgBox "Invalid"
Exit Function
End If

ReDim arySheets(iEnd - iStart)
For i = iStart To iEnd
arySheets(i - iStart) = ActiveWorkbook.Worksheets(i).Name
Next i

Sheets(arySheets).Select

End Function



--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"J.W. Aldridge" wrote in message
oups.com...
I have several macros that I need to record where I group sheets, then
perform the actions.
I need a code that will group sheets by sheetname range (i.e. "apples"
to "oranges").
I will record myself perfoming the various actions to get the code to
finish it, however, I need a general/ basic grouping code to start off.



Thanx.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 425
Default Group sheets using code

I'm sure it will work, but I'm having some trouble figuring out where
to place a function.
I'm used to sub - macro's. Should there be a heading?
As stated before, I will add-in the procedures I need towards the end.


Thanx.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Group sheets using code

Place it in a standard code module. It will work just the same as a sub.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"J.W. Aldridge" wrote in message
oups.com...
I'm sure it will work, but I'm having some trouble figuring out where
to place a function.
I'm used to sub - macro's. Should there be a heading?
As stated before, I will add-in the procedures I need towards the end.


Thanx.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Group sheets using code

You can just call Bob's code the same as any other code. If you wish you can
even change the word function to sub. The only not is that the sheet Apple
must come before the sheet Orange and none of the sheets in the middle may be
hidden...

sub Test
Call GroupSheets("Apple", "Orange")
end sub

Public Sub GroupSheets(StartSheet As String, EndSheet As String)
Dim iStart As Long
Dim iEnd As Long
Dim i As Long, j As Long
Dim arySheets

On Error Resume Next
iStart = ActiveWorkbook.Worksheets(StartSheet).Index
iEnd = ActiveWorkbook.Worksheets(EndSheet).Index
On Error GoTo 0
If iStart = 0 Or iEnd = 0 Or iEnd < iStart Then
MsgBox "Invalid"
Exit Function
End If

ReDim arySheets(iEnd - iStart)
For i = iStart To iEnd
arySheets(i - iStart) = ActiveWorkbook.Worksheets(i).Name
Next i

Sheets(arySheets).Select

End Sub


--
HTH...

Jim Thomlinson


"J.W. Aldridge" wrote:

I'm sure it will work, but I'm having some trouble figuring out where
to place a function.
I'm used to sub - macro's. Should there be a heading?
As stated before, I will add-in the procedures I need towards the end.


Thanx.


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
Name a group of sheets Mary Ann Excel Discussion (Misc queries) 2 November 26th 09 10:59 PM
sort between a group of sheets tkincaid Excel Worksheet Functions 8 January 6th 09 03:42 PM
Group Sheets Brian Keanie Excel Discussion (Misc queries) 10 January 1st 05 08:34 PM
Need group all sheets in a workbook TOMB Excel Programming 2 November 16th 04 03:58 PM
Sheets Protection for group!!!!? Simon Lloyd[_488_] Excel Programming 3 June 16th 04 12:12 PM


All times are GMT +1. The time now is 01:59 PM.

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"