Out range error –

Hello Everyone,

I am trying to use an Input Box to prompt member to input a 7 digit number starting with 6, for example, “6014342” to select the worksheet to print.  I want to trap error if the number is not 7 digits long or does not start with a “6” or is a blank or an alphabet string.

The following is causing out of range error 9

Private Sub WorkSheetName_Click()

Dim SheetName As String

SheetName = Application.InputBox(“Enter a sheet number”)

If len(WorkSheetName) <> 7 then

Msgbox ”The number should be 7 digits long!”

Elseif left(WorksheetName, 1) <> 6 then

Msgbox ”The number should begin with 6!”

End if


MsgBox “Sheet for ” & SheetName & ” — Printed!”

End Sub

Please help


Thank you



Add Comment
0 Answer(s)
  • Found this useful?

    Please share using the share button above.

    If you found the answer is best answer for your question, Please mark as 'best answer' by clicking on the right tick mark icon at the left side of the answer.

    Found the answer useful and wants to credit the user, then vote the answer (vote up).

  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.