OilEconomist
Active Member
- Joined
- Dec 26, 2016
- Messages
- 421
- Office Version
- 2019
- Platform
- Windows
Thanks in advance. I will try to post feedback whether it works or not. Also, please feel free to clean up my code as I'm still learning how to write code.
I am trying to set a cell to the date and time in the format of "YYYY-MM-DD", "HH:MM:SS AM/PM"
(1) So first I set the cell to today by using the now function Cell.Formula = Now()
(2) Format the cell to where it will look this for today "2020-05-13, 07:29:10 AM"
I also would like to wrap the text to where "2020-05-13," is on the top and "07:29:10 AM" is underneath it.
I already have the column width set and wrap text set.
Please note, I would like to add a comma in there.
Once again thanks!
I am trying to set a cell to the date and time in the format of "YYYY-MM-DD", "HH:MM:SS AM/PM"
(1) So first I set the cell to today by using the now function Cell.Formula = Now()
(2) Format the cell to where it will look this for today "2020-05-13, 07:29:10 AM"
I also would like to wrap the text to where "2020-05-13," is on the top and "07:29:10 AM" is underneath it.
I already have the column width set and wrap text set.
Please note, I would like to add a comma in there.
Code:
'Activate the worksheet
Worksheets("Sheet1").Activate
'Set the cell to the date and time and format
'Set Cell to the date and time
Cells(2, 3).Select
Cells(2, 3).Formula = "=NOW()"
Selection.NumberFormat = "yyyy-mm-dd, hh:mm:ss AM/PM"
Cells(2, 3).Value = Cells(2, 3).Value
'Set the column width and format the cell
With Selection
.ColumnWidth = 11.36
.Font.Bold = True
.WrapText = True
End With
Once again thanks!