I'm trying with VBA to convert a date format in a table column so that I can use it in formulas.
The column contains dates with format "general", not "date" and looks like this: 13/04/2019. So it needs to be dd/mm/yyyy and recognized as a date.
I've looked up online and struggle to find something that works. I've tried:
.numberformat = "dd/mm/yyyy"
but it didn't work
This is the code I'm trying.
With wsDormant.ListObjects("Table_Dormant_Stock").ListColumns.Add
.DataBodyRange.Formula = "=DATE(RIGHT([@[Days Last Sold]],4), MID([@[Days Last Sold]],3,2), LEFT([@[Days Last Sold]],2))"
End With
'Change date to amount of days
With wsDormant.ListObjects("Table_Dormant_Stock").ListColumns.Add
.DataBodyRange.Formula = "=DAYS($C$8,[Days Last Sold])"
wsDormant.ListObjects("Table_Dormant_Stock").ListColumns("Days Last Sold").DataBodyRange.Value = .DataBodyRange.Value
.Delete
End With
I'm getting #value when I try the formula. It needs to convert the cell format to date. The formulas that uses dates don't seem to like the date format in dd/mm/yyyy. But are happy with yyyy/mm/dd.