Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stuck. I need some VBA code to insert double-quotes around strings in each cell in an excel range

Tags:

excel

vba

I'm familiar with VB.NET, but VBA in excel has me stumped. With my best attempt, I get a "Type mismatch" error:

Sub AddQuotes()

    For Each x In Range("List").Cells
    x.Text = "*" * " & x.text & " & "*"
    Next

End Sub
like image 461
cmm Avatar asked May 17 '10 21:05

cmm


People also ask

How do I put double quotes in a string VBA?

I find the easiest way is to double up on the quotes to handle a quote. *Note: CHAR() is used as an Excel cell formula, e.g. writing "=CHAR(34)" in a cell, but for VBA code you use the CHR() function.

What is CHR 34 in VBA?

CHR is the VBA function and returns the character from the ASCII table. For example, Chr(34) returns 34th character, which is the “ sign (double quotes).


1 Answers

Try using chr(34) for the double-quote character

eg chr(34) & x.text & chr(34)

like image 68
Tom Womack Avatar answered Sep 30 '22 08:09

Tom Womack