View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson Jim Thomlinson is offline
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.