ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   vbCr (https://www.excelbanter.com/excel-programming/389735-vbcr.html)

jimmy[_5_]

vbCr
 
Hi,

I tried to use vbCr in the caption property of commandbutton is work but it
doesn't work in putting contents in a cell, what is the code to get the
result like pressing "Alt + Enter" in a cell?

Thanks



JLatham

vbCr
 
Try something like this for cells. I just picked H1 because it was handy:

Range("H1").NumberFormat = "@" ' set to text format
Range("H1") = "Hello" & vbLf & "goodbye." 'use vbLf vs vbCr or vbCrLf
Range("H1").WrapText = True ' hides the little square box


"jimmy" wrote:

Hi,

I tried to use vbCr in the caption property of commandbutton is work but it
doesn't work in putting contents in a cell, what is the code to get the
result like pressing "Alt + Enter" in a cell?

Thanks




Peter T

vbCr
 
If it's a Commandbutton on a userform1, at runtime -

CommandButton1.Caption = "First Line" & vbCr & "Second line"

To set at design time probably simplest to copy the two line text from a
cell into the caption property.

If is a commandbutton on a worksheet, in the immediate window (ctrl-g) -

ActiveSheet.oleobjects("CommandButton1").object.ca ption = "first" & vbcr &
"second"

with the cursor at the end of the line hit Enter

Regards,
Peter T


"jimmy" wrote in message ...
Hi,

I tried to use vbCr in the caption property of commandbutton is work but

it
doesn't work in putting contents in a cell, what is the code to get the
result like pressing "Alt + Enter" in a cell?

Thanks






All times are GMT +1. The time now is 04:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com