I have some issue with my VBA code. I got Date variable that stored as dd/mm/yyyy
but when I write the date to a specific cell the format change to mm/dd/yyyy
, I have been trying many options but none of them worked for me, I also check that the variable know what is the current day, month and year.
The code:
Sheets("report_orders").Select
Range("A1").Value = customerName
Range("A2").Value = "äæîðä " & orderID
Range("A3").Value = "äæîðä ì÷åç " & orderPo
'Range("B2").Value = orderDate
Range("B2").Value = Day(orderDate) & "/" & Month(orderDate) & "/" & Year(orderDate)
Debug.Print "year " & Year(orderDate)
Debug.Print "month " & Month(orderDate)
Debug.Print "day " & Day(orderDate)
but the result is :
Format()
function. – Harun24HRDate variable that stored as dd/mm/yyyy
- it isn't stored that way becauseDate
variables do not have a format. You should remove your code and replace it withRange("B2").Value = orderDate
, and you should apply the date formatting that you want to the cell. – GSergRange("B2").NumberFormat = "mm/dd/yyyy"
and thenRange("B2").Value = orderDate
. It iwll definitely work – Siddharth Rout