CHR is the VBA function and returns the character from the ASCII table.
For example, Chr(34) returns the 34th character, which is the “ sign (double quotes).
Example:
Look at this example. Let’s say that you want to insert the following name into the cell using the VBA code.
Edwin “Buzz” Aldrin
You can use one of the two methods.
- “Edwin “”Buzz”” Aldrin”
- “Edwin “ & chr(34) & “Buzz” & chr(34) & “ Aldrin“
To illustrate how you can Execute the following macro inside a cell, use this formula.
1 2 3 |
Sub InsertText() ActiveCell.Value = "Edwin " & Chr(34) & "Buzz" & Chr(34) & " Aldrin" End Sub |
Both examples will display the name in double quotes.
CAUTION
Don’t confuse the chr function with the CHAR function. The first one is used in VBA, and the second one is in Excel.