Home > Enterprise >  how to get msgbox text from reference cell, which includes newline characters
how to get msgbox text from reference cell, which includes newline characters

Time:11-02

edit: all responses have missed my point, so i've removed any mention of special characters and just want to focus on the line break vbCrLf

i have a combobox populated from a range of cells, and i want a msgbox to pop up based on the user's selection in said combobox, such that the msgbox text is taken from a cell which corresponds to the user's selected cell (i.e. the cell linked to the user's cbox selection). for example:

user selection msgbox text
scarf It's 40 degrees.
Are you sure you want a scarf?
swimshorts Don't forget your sunscreen!

so that's the reason for trying to fill the cbox from a cell, rather than from VB.

my problem is how to write the newline and special character in the reference cell and have msgbox format it correctly.

i.e. MsgBox "It's 40 degrees." & vbCrLf & "Are you sure you want a scarf?" does what i want, but if i place that text in a cell and then try to reference that cell with a msgbox, e.g. MsgBox Sheet1.Range("B2"), then the msgbox just prints the text without formatting.

e.g. enter image description here

If you are entering it from VBA, then the code line would be:

Range("A1")  = "abc" & vblf & "def"
  • Related