?
Solved

Excel date format display issue

Posted on 2015-01-12
5
Medium Priority
?
212 Views
Last Modified: 2015-01-12
Hi,

Attached excel sheet I want to convert date format in Red columns into dd/mm/yyyy
file0.xlsx
0
Comment
Question by:a500505077
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 13

Expert Comment

by:akb
ID: 40544040
The dates in the red columns are not really dates, they are numbers. You need to convert them to strings and then extract the required elements and convert them to dates.
The formula is:
=CONCATENATE(LEFT(TEXT(F2,"00000000"),2),"/",MID(TEXT(F2,"00000000"),3,2),"/",MID(TEXT(F2,"00000000"),5,4))
where the date is in cell F2.
See the attached file.

TEXT(F2,"00000000") converts the number to text and pads it on the left with zeros for the short dates.
file0.xlsx
0
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 2000 total points
ID: 40544069
You can use this macro if the column headers are colored as in the file given by you

Sub txt2date()
    Dim cel As Range
    For Each col In Range("1:1")
    If col.Interior.Color = 255 Then
    For Each cel In col.EntireColumn.Cells
        'cel.Select
        If cel.Row > 1 Then
            If Trim(cel) <> "" Then
                cel = DateSerial(Right(cel, 4), Mid(cel, Len(cel) - 5, 2), Left(cel, Len(cel) - 6))
                cel.NumberFormat = "dd/mm/yyyy"
            End If
        End If
        Next cel
        End If
    Next col
End Sub

Open in new window

0
 
LVL 33

Expert Comment

by:Rob Henson
ID: 40544232
A shorter formula:

=DATE(RIGHT(B2,4),MID(B2,LEN(B2)-5,2),LEFT(B2,LEN(B2)-6))

Allows for the ddmmyyyy and the dmmyyyy formats.

Put the above formula into column AN and then copy and paste to columns AR, AZ, BE and BF, You can then copy this whole block (AN to BF) and paste values back onto the original data, select the skip blanks option so it doesn't overwrite the values of the columns between.

Thanks
Rob H
0
 
LVL 81

Expert Comment

by:byundt
ID: 40544828
I assume that the columns aren't actually colored red when you want to run the macro. I therefore specified the columns to be converted in the following macro:
Sub DateConverter()
Dim v As Variant
Dim cel As Range, rg As Range
Application.ScreenUpdating = False
With ActiveSheet
    For Each v In Array("B", "F", "N", "S", "T")
        Set rg = Intersect(.Columns(v), .UsedRange)
        For Each cel In rg.Cells
            If IsNumeric(cel.Value) Then
                cel.Value = Format(cel.Value, "00\/00\/0000")
            End If
        Next
        rg.TextToColumns Destination:= _
            rg.Cells(1), DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
            Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(1, 4), TrailingMinusNumbers:=True
        rg.NumberFormat = "dd/mm/yyyy"
    Next
End With
End Sub

Open in new window

0
 
LVL 81

Expert Comment

by:byundt
ID: 40544845
And if you want a formula solution and your default date format is dd/mm/yyyy:
=--TEXT(B2,"00\/00\/0000")
You will need to format the column as dd/mm/yyyy, as the values will otherwise appear to be numbers like 40384.

The above formula will not work in all cases if your default date format is mm/dd/yyyy. In particular, an ambiguous date like 03/05/2014 will be converted to March 5, 2014 rather than the desired 3 May 2014.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question