Edited) is this right? I need to do the same thign for column P. Should I do another for loop?
Dim i As Long
For i = 1 To Rows.Count
If Len(Cells(i, "Q").Value) <= 4 Then
Cells(i, 1).NumberFormat = "01/01/yyyy"
Else: Cells(i, "Q").NumberFormat = "MM/DD/YYYY"
End If
Next i
When I import excel file to access, the column that has either the years(19xx) or a full date don't display properly after imported. The years seem fine but full date is changed to a random number like 39213, etc. So I tried to format the whole column to text and export to access, the same thing happens. What should I do? The original column is in 'general' format
01/01/1962
01/01/1966
01/01/1956
1964
01/01/1943
01/01/1943
01/01/1964
1964
01/01/1972
01/01/1948
01/01/1961
01/01/1953
01/01/1961
01/01/1963
01/01/1963
01/01/1973
1960
01/01/1956
01/01/1940
1958
1958
1955
01/01/1948
01/01/1948
01/01/1970
1959
1964
01/01/1975
1966
This becomes
22647
24108
20455
1964
15707
15707
19
23377
1964
26299
17533
22282
19360
22282
23012
23012
26665
1960
20455
14611
1958
1958
1955
17533
17533
25569
1959
1964
27395
1966
And the latter column is in 'Text' format. I dont know what is wrong
EDITED TO CORRECT FORMAT ISSUE!!
Depending on which approach you want to take (A. Fix in Excel; B. Fix in Access), your solution will vary. To use your code, I modified slightly.
WARNING!! If only a year, my code will destroy content of column 1!! Change to suit your needs.
I think the date format should be "MM/DD/YYYY" across all the rows of "Q". I have modified your code slightly.
After executing all the dates in the column "Q" will be formatted to "MM/DD/YYYY"
And if you want to keep the formatting year with 4 digits in the Q column and format that year separately in column 1, then use the below code