View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rowan Drummond[_3_] Rowan Drummond[_3_] is offline
external usenet poster
 
Posts: 414
Default Why Error Message "End Select without Select Case"?

You were actally missing an End With. Try:

Private Sub Worksheet_Activate()
Dim wSheet As Worksheet
Dim wSheetIndex As Long
Dim M As Long
M = 1
Application.ScreenUpdating = False
ActiveSheet.Unprotect ' Unprotect "Index" sheet
With Me
.Columns(1).ClearContents
.Cells(1, 1) = "Customer Index"
.Cells(1, 1).Name = "Index"
End With

For Each wSheet In Worksheets
' Don't want an index entry for MenuSheet or New Customer
Select Case wSheet.Name
Case Not Me.Name
Case Not "MenuSheet"
Case Not "New Customer"
Case Else
M = M + 2
' Add 'Return to Index' link on worksheet
' format it to bold yellow with full centering
With wSheet
.Unprotect
.Range("A1").Name = "Start" & wSheet.Index
.Hyperlinks.Add Anchor:=.Range("B1:C1"), Address:="", _
SubAddress:="Index", TextToDisplay:="Return to Index"
With .Cells.Range("B1:C1")
.Merge
.Interior.ColorIndex = 6
.Interior.Pattern = xlSolid
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.Font.Bold = True
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlEdgeLeft).LineStyle = xlContinuous
End With
.Protect '<<changed
End With '<<Added
End Select
Next wSheet
Application.ScreenUpdating = True
ActiveSheet.Protect ' Protect Index sheet
End Sub

Hope this helps
Rowan


GoFigure wrote:
The following is a modification of a procedure to create a first-sheet
"Index" of all worksheets in a workbook that's located in multiple
places around the Web. I do not want it to create index entries for the
Index sheet and two others with the names "MenuSheet" and "New
Customer".

But when it runs, it generates the compile error ""End Select without
Select Case" even though there's clearly a Select Case statement and
only one.

What's wrong here?


Code:
--------------------
Private Sub Worksheet_Activate()
Dim wSheet As Worksheet
Dim wSheetIndex As Long
Dim M As Long
M = 1
Application.ScreenUpdating = False
ActiveSheet.Unprotect ' Unprotect "Index" sheet
With Me
.Columns(1).ClearContents
.Cells(1, 1) = "Customer Index"
.Cells(1, 1).Name = "Index"
End With

For Each wSheet In Worksheets
' Don't want an index entry for MenuSheet or New Customer
Select Case wSheet.Name
Case Not Me.Name
Case Not "MenuSheet"
Case Not "New Customer"
Case Else
M = M + 2
' Add 'Return to Index' link on worksheet
' format it to bold yellow with full centering
With wSheet
.Unprotect
.Range("A1").Name = "Start" & wSheet.Index
.Hyperlinks.Add Anchor:=.Range("B1:C1"), Address:="", _
SubAddress:="Index", TextToDisplay:="Return to Index"
With .Cells.Range("B1:C1")
.Merge
.Interior.ColorIndex = 6
.Interior.Pattern = xlSolid
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.Font.Bold = True
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlEdgeLeft).LineStyle = xlContinuous
End With
wSheet.Protect
End Select
Next wSheet
Application.ScreenUpdating = True
ActiveSheet.Protect ' Protect Index sheet
End Sub
--------------------


Many thanks,

- Al