Type mismatch error with Chr(34)

he4dhuntr

New Member
Joined
Jan 15, 2009
Messages
7
Hi all,

I'm getting an error when I try to use a string with the Chr(34) in Excel 2007. I had a somewhat long string calculation giving me the error, but I tried to test it with a simple one. Here's the example code:

Code:
Sub Test()
    Dim a As String
    a = Chr(34) And "This is a test" And Chr(34)
    Sheets(1).Cells(1, 1).Value = a
End Sub

I get this error on the "a = ..." line:

Run-time error '13': Type mismatch

I've searched around, but for the life of me can't figure out what could be wrong.

Thanks for any help!

Cheers,
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
"And" is an operator for creating conditional statements. What you need is "&":

Code:
Sub Test()
    Dim a As String
    a = Chr(34) [B][COLOR=red]&[/COLOR][/B] "This is a test" [COLOR=red][B]&[/B][/COLOR] Chr(34)
    Sheets(1).Cells(1, 1).Value = a
End Sub
 
Upvote 0
It's not stupid if you get something wrong the first time you try to do it.

Stupid would be if you did it wrong the second time! :)
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,728
Members
452,939
Latest member
WCrawford

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