Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Select and Sort by tab color - crashes Excel

My code below works as long as it finds that tab color, but in the event
there are no tabs with this colorindex it crashes Excel completely. My tabs
colors are assigned earlier in the process by criteria. It is looking for
seasonal employees, which we will not have until March so when this part of
the code runs it crashes. Is there an easy workaround?

Sub Select1seasonal()
Dim s() As String
Dim ws As Worksheet
Dim i As Integer
i = 0
For Each ws In Worksheets
If ws.Tab.ColorIndex = 37 Then
ReDim Preserve s(i)
s(i) = ws.Name
i = i + 1
End If
Next ws
Worksheets(s).Select

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Select and Sort by tab color - crashes Excel

If no tabs are found, you are telling Excel to select a non-existent
worksheet using an empty array as the worksheet name.
That's probably the reason for the crash.
If any tab has the proper color the value of i will not be zero so
you can use this below the "Next ws" line...
'--
If i 0 Then
Worksheets(s).Select
Else
MsgBox "No worksheets found. "
End If
--
Jim Cone
Portland, Oregon USA


"jeremiah"

wrote in message
My code below works as long as it finds that tab color, but in the event
there are no tabs with this colorindex it crashes Excel completely. My tabs
colors are assigned earlier in the process by criteria. It is looking for
seasonal employees, which we will not have until March so when this part of
the code runs it crashes. Is there an easy workaround?

Sub Select1seasonal()
Dim s() As String
Dim ws As Worksheet
Dim i As Integer
i = 0
For Each ws In Worksheets
If ws.Tab.ColorIndex = 37 Then
ReDim Preserve s(i)
s(i) = ws.Name
i = i + 1
End If
Next ws
Worksheets(s).Select

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Select and Sort by tab color - crashes Excel

Fortunately have have the variable i:

Sub Select1seasonal()
Dim s() As String
Dim ws As Worksheet
Dim i As Integer
i = 0
For Each ws In Worksheets
If ws.Tab.ColorIndex = 37 Then
ReDim Preserve s(i)
s(i) = ws.Name
i = i + 1
End If
Next ws
If i < 0 Then
Worksheets(s).Select
End If
End Sub

--
Gary''s Student - gsnu200831


"jeremiah" wrote:

My code below works as long as it finds that tab color, but in the event
there are no tabs with this colorindex it crashes Excel completely. My tabs
colors are assigned earlier in the process by criteria. It is looking for
seasonal employees, which we will not have until March so when this part of
the code runs it crashes. Is there an easy workaround?

Sub Select1seasonal()
Dim s() As String
Dim ws As Worksheet
Dim i As Integer
i = 0
For Each ws In Worksheets
If ws.Tab.ColorIndex = 37 Then
ReDim Preserve s(i)
s(i) = ws.Name
i = i + 1
End If
Next ws
Worksheets(s).Select

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Select and Sort by tab color - crashes Excel

Once again, you guys have saved me. Thank you...
"Gary''s Student" wrote:

Fortunately have have the variable i:

Sub Select1seasonal()
Dim s() As String
Dim ws As Worksheet
Dim i As Integer
i = 0
For Each ws In Worksheets
If ws.Tab.ColorIndex = 37 Then
ReDim Preserve s(i)
s(i) = ws.Name
i = i + 1
End If
Next ws
If i < 0 Then
Worksheets(s).Select
End If
End Sub

--
Gary''s Student - gsnu200831


"jeremiah" wrote:

My code below works as long as it finds that tab color, but in the event
there are no tabs with this colorindex it crashes Excel completely. My tabs
colors are assigned earlier in the process by criteria. It is looking for
seasonal employees, which we will not have until March so when this part of
the code runs it crashes. Is there an easy workaround?

Sub Select1seasonal()
Dim s() As String
Dim ws As Worksheet
Dim i As Integer
i = 0
For Each ws In Worksheets
If ws.Tab.ColorIndex = 37 Then
ReDim Preserve s(i)
s(i) = ws.Name
i = i + 1
End If
Next ws
Worksheets(s).Select

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 364
Default Select and Sort by tab color - crashes Excel

you don't even need to use an array, and thus have to worry about a
non-existent sheet.

Sub Select1seasonal()
Dim i As Long
For i = 1 To Worksheets.Count
If Worksheets(i).Tab.ColorIndex = 37 Then
Worksheets(i).Select False
End If
Next
End Sub


--


Gary K



"jeremiah" wrote in message
...
My code below works as long as it finds that tab color, but in the event
there are no tabs with this colorindex it crashes Excel completely. My tabs
colors are assigned earlier in the process by criteria. It is looking for
seasonal employees, which we will not have until March so when this part of
the code runs it crashes. Is there an easy workaround?

Sub Select1seasonal()
Dim s() As String
Dim ws As Worksheet
Dim i As Integer
i = 0
For Each ws In Worksheets
If ws.Tab.ColorIndex = 37 Then
ReDim Preserve s(i)
s(i) = ws.Name
i = i + 1
End If
Next ws
Worksheets(s).Select

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
In Excel it would help a lot to be able to sort rows by color Jeff Watkins Excel Discussion (Misc queries) 7 March 13th 06 09:06 PM
Excel sort by Fill Color by custom list sort Dash4Cash Excel Discussion (Misc queries) 2 July 29th 05 10:45 PM
Is there a way to Sort data by color in Excel? SRTUC Excel Discussion (Misc queries) 2 July 1st 05 06:35 PM
Font color crashes! okopk Excel Discussion (Misc queries) 3 April 12th 05 02:53 AM
Excel 2000 VBA Sort without Select Matt. Excel Programming 7 January 13th 04 08:36 PM


All times are GMT +1. The time now is 01:53 AM.

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

About Us

"It's about Microsoft Excel"