VBA to insert second line in cell

ExcelNoob222

Board Regular
Joined
Jun 17, 2020
Messages
77
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have the below VBA:

Range("A1").Formula = "=""Last Updated: ""&TEXT(NOW(),""mm/dd/yyyy hh:mm"")&"" Current week: ""&Tracking!K2"

which gives me the following "Last Updated: 05/25/2022 10:05 Current week: 2"

I want it to look like this though:

"Last Updated: 05/25/2022 10:05
Current week: 2"


I have tried the below codes but i get a #name? error.

Range("A1").Formula = "=""Last Updated: ""&TEXT(NOW(),""mm/dd/yyyy hh:mm"")& CHR(10) &"" Current week: ""&Tracking!K2"
Range("A1").Formula = "=""Last Updated: ""&TEXT(NOW(),""mm/dd/yyyy hh:mm"")& CHR(13) &"" Current week: ""&Tracking!K2"
Range("A1").Formula = "=""Last Updated: ""&TEXT(NOW(),""mm/dd/yyyy hh:mm"")& vbLf &"" Current week: ""&Tracking!K2"

Any ideas? Thanks!
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
It should be CHAR not CHR
 
Upvote 0
Solution
Chr(10) is correct, but you must format the cell and check the Wrap box on the alignment tab.
Sorry, please disregard this answer, it is nonsense :)
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,206
Messages
6,123,638
Members
449,109
Latest member
Sebas8956

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