Error is thrown when I enter a name in the input box with an apostrophe in it e.g. Son's

Balrajss0121

New Member
Joined
May 6, 2020
Messages
11
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi, I am having an issue with the code below. Every time it runs and I enter a company name with an apostrophe an error is thrown that reads 'type mismatch run time error 13'. I am fairly new to vba, I have however tried to double up on the quotation marks *If Evaluate("isref('"" & ActNm & ""'!A1)") Then*. This did stop the issue but then it stops the line underneath from running and excel runs its own error for duplicated names. Any help would be appreciated on how to get rid of this. Thank you :)

Sub CopySheetAndRename()
Dim ActNm As String

ActNm = InputBox("Please Enter the Clients Company Name.")
If ActNm = "" Then Exit Sub
If Evaluate("isref('" & ActNm & "'!A1)") Then
MsgBox "This Company Backup Sheet already exists!"
Exit Sub
End If
Application.ScreenUpdating = False
With ActiveWorkbook
.Sheets("MASTER SHEET").Visible = True
.Sheets("MASTER SHEET").Copy , .Sheets("MASTER SHEET")
ActiveSheet.Name = ActNm
.Sheets("MASTER SHEET").Visible = False
End With
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Sheet tab names cannot contain the characters /, \, [, ], *, ?, or :
And neither apostrophe '

You can put a validation to not allow the entry of those characters.

Edit:
Check this
 
Upvote 0
Okay thank you for that insightful information. I will make use of the validation instead :)
 
Upvote 0

Forum statistics

Threads
1,215,811
Messages
6,127,017
Members
449,351
Latest member
Sylvine

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