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

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
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,214,386
Messages
6,119,215
Members
448,874
Latest member
b1step2far

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