• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Help with Macro Dialog Box/loop

Gman87

New Member
Hello,

I have a code to look up and go to a sheet name, it functions as intended but the cancel button does not work.

Can someone please tell me how to either make the cancel button work to cancel the command or to end the loop with out getting a error message

Below is the code

Thank you


Code:
Function WorksheetExists(WSName As String) As Boolean
  On Error Resume Next
  WorksheetExists = Worksheets(WSName).Name = WSName
  On Error GoTo 0
End Function

Sub GotoSheet()
Dim shname As String
Do Until WorksheetExists(shname)
  shname = InputBox("Enter Tank Code")
  If Not WorksheetExists(shname) Then MsgBox shname & " Tank Code Doesn't Exist in File", vbExclamation
Loop
Sheets(shname).Select
End Sub
 
You missed Exit Sub ... like
Code:
Function WorksheetExists(WSName As String) As Boolean
    On Error Resume Next
        WorksheetExists = Worksheets(WSName).Name = WSName
    On Error GoTo 0
End Function

Sub GotoSheet()
Dim shname As String
    Do Until WorksheetExists(shname)
        shname = InputBox("Enter Tank Code")
        If Not WorksheetExists(shname) Then
            MsgBox shname & " Tank Code Doesn't Exist in File", vbExclamation
            Exit Sub
        End If
    Loop
    Sheets(shname).Select
End Sub
 
Back
Top