Type Mismatch

AngelK

New Member
Joined
Aug 4, 2016
Messages
34
I have a code that creates a new sheet for each list of names in Sheet1. The problem I'm having is when the name has an apostrophe in it (such a O'Donnell), I'm getting a type mismatch error here:

If Not Evaluate("ISREF('" & CStr(N.Text) & "'!A1)")

Any suggestions for this VB newbie? Thanks

Code:
Sub CreateReportCards()
    Dim wsTch As Worksheet, wsTmp As Worksheet
    Dim shtNames As Range, N As Range

    Set wsTmp = Sheets("Template")
    Set wsTch = Sheets("Teacher")
    Set shtNames = wsTch.Range("C2:C" & Rows.Count).SpecialCells(xlConstants)
    
Application.ScreenUpdating = False
    For Each N In shtNames
        If Not Evaluate("ISREF('" & CStr(N.Text) & "'!A1)") Then
          wsTmp.Copy After:=Sheets(Sheets.Count)
            ActiveSheet.name = CStr(N.Text)
              ActiveSheet.Range("C5") = CStr(N.Text)
              End If
         Next N

wsTch.Select
End Sub
 
Last edited:

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Try the following...

Code:
If Not Evaluate("ISREF('" & [COLOR=#ff0000]Replace(N.Text, "'", "''")[/COLOR] & "'!A1)") Then

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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