Below is my code. I am writing a Macro to go on a button on the first page of an excel report that will take users to different tabs in the report based on the number they use. The issue is if I use the integer variable, if a user cancels the box or hits the x a error occurs. The numbers work fine in regards to the sheets with this. However, if i dim it as Variant an error no longer occurs, but then the numbers input no longer work. For ex. 3 brings up the invalid sheet box even if there are 8 sheets in the workbook. I think the variant is causing the input numbers to be a different format from integer? I think I can use the on error resume, but I was just wondering what that would look like. Or if there is another way to do this without using that method
Public Sub Summary_select()
Dim x As Integer
x = InputBox("Please Input The Sheet Number")
If Not (IsNumeric(x)) Then
MsgBox ("User Cancelled")
ElseIf x = 0 Then
MsgBox ("User Entered an Invalid Number of sheets")
ElseIf x > Sheets.Count Then
MsgBox ("User Entered an Invalid Number of sheets")
Else
Sheets(x).Activate
Range("A1").Select
End If
End Sub