Application Goto Reference

Halos

New Member
Joined
Feb 14, 2015
Messages
34
Hello,

I created userform and added Application Goto reference in a code. The code is, when I add sheet name to the textbox5 then application goto reference goes to that sheet. But if that sheet doesn't exist, which code do I need to get msgbox that "sheet doesn't exist"? Please see below my code:

Code:
Private Sub CommandButton1_Click()
              
    Application.Goto Reference:=(TextBox5) & "!R1C1"

   
End Sub

Thanks in advance
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Try this.
Code:
Dim strRef As String

    strRef = TextBox5.Value & "!R1C10"
    
    If Evaluate("ISREF(" & TextBox5.Value & "!A1)") Then
        Application.Goto ReferencE:=strRef
    End If
 
Upvote 0
Try this.
Code:
Dim strRef As String

    strRef = TextBox5.Value & "!R1C10"
    
    If Evaluate("ISREF(" & TextBox5.Value & "!A1)") Then
        Application.Goto ReferencE:=strRef
    End If

Thanks for the response but code doesn't work. Please see below code and help:

Code:
Private Sub CommandButton1_Click()
             
    Application.Goto Reference:=(TextBox5) & "!R1C1"
    
'which code do I need to put here - get error message via msgbox, if there is no exist that "sheet name" which I put in TextBox5...

   
Unload yeniUserform1
End Sub
 
Upvote 0
How about
Code:
Private Sub CommandButton1_Click()
   
   If Evaluate("isref('" & TextBox5.Value & "'!A1)") Then
      Application.Goto Reference:=TextBox5.Value & "!R1C1"
   Else
      MsgBox "Sheet " & TextBox5.Value & " doen't exist"
   End If
   Unload yeniUserform1
End Sub
 
Upvote 0
How about
Code:
Private Sub CommandButton1_Click()
   
   If Evaluate("isref('" & TextBox5.Value & "'!A1)") Then
      Application.Goto Reference:=TextBox5.Value & "!R1C1"
   Else
      MsgBox "Sheet " & TextBox5.Value & " doen't exist"
   End If
   Unload yeniUserform1
End Sub

Thanks, it is working now.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0
Kind of curious, did the code I posted cause an error?
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,217
Members
452,619
Latest member
Shiv1198

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top