VBA - run time error '13' type mismatch selecting sheet based on named range

TBD8913

New Member
Joined
Dec 6, 2017
Messages
2
Hi everyone,

Please can someone help me with the following, apologies if this is quite basic. I've not done any VBA for a long time and I'm out of practice.

In my Excel workbook I have a number of buttons to take you to different sheets in the model, I'm trying to write code that can be assigned to all buttons that pulls through from a range so I can easily update it in future.

Code:
Sub Sheet_Tab()
Dim sheetname As Range
 Sheets("Controls").Range("SelectedSheet") = ActiveSheet.Shapes(Application.Caller).TextFrame.Characters.Text
 Set sheetname = Sheets("Controls").Range("SheetTabName")
 Sheets(sheetname).Select
End Sub

I'm getting a run time 13 error, when I hover over sheetname, it is pulling through the right range, so I'm a bit confused as to what is causing this.

Thanks in advance.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
What is Range("SelectedSheet")?
What is .Range("SheetTabName")

What line does the error occur?
 
Last edited:
Upvote 0
Thanks for your reply.

I've fixed the problem by using referring to the sheet number rather than sheet name, in case anyone else has a similar problem in the future.
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,843
Members
449,051
Latest member
excelquestion515

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