Hi all
VBA novice here. I am trying to write a VBA code to convert YYYYMMDD to dd/mm/yyyy format however my range has some 0 values. I have tried writing the below code based on other threads on the board however I keep getting an error "Type mismatch".
I am essentially trying to 'hide' the 0 values and converting all others to dd/mm/yyyy date format. Any help would be greatly appreciated!
Cheers!
VBA novice here. I am trying to write a VBA code to convert YYYYMMDD to dd/mm/yyyy format however my range has some 0 values. I have tried writing the below code based on other threads on the board however I keep getting an error "Type mismatch".
I am essentially trying to 'hide' the 0 values and converting all others to dd/mm/yyyy date format. Any help would be greatly appreciated!
VBA Code:
Dim c As Range
Application.ScreenUpdating = False
For Each c In Range("H2:H" & Cells(Rows.Count, "H").End(xlUp).Row)
If c.Value = 0 Then c.NumberFormat = "#;#;" Else
c.Value = DateSerial(Left(c.Value, 4), Mid(c.Value, 5, 2), Right(c.Value, 2))
c.NumberFormat = "dd/mm/yyyy"
Next
Application.ScreenUpdating = False
Last edited by a moderator: