vba help - date issue

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
843
Office Version
  1. 2010
Platform
  1. Windows
Hi Team,

I am splitting Column A Data, and updating it in Column B.
Column A data is in DD/MM/YYYY Format, while pasting values are getting pasted in mm/dd/yyyy format.

How to solve it.


Expected output is in Column D. ... Macro is giving Column B output.

Book4
ABCD
1DateMax DateExpected
230-01-2020/02-09-2019/16-09-201930/01/202030/01/2020
304-09-2019/18-09-2019/14-10-2019/23-01-202023/01/202023/01/2020
418-09-2019/30-09-2019/05-11-2019/23-01-202023/01/202023/01/2020
516-09-2019/25-09-2019/04-11-201911/04/201904/11/2019
601-10-2019/23-01-2020/09-10-2019/04-11-201923/01/202023/01/2020
701-10-2019/28-10-2019/30-01-2020/11-11-201930/01/202030/01/2020
803-02-2020/01-10-2019/30-01-202002/03/202003/02/2020
Sheet1



'Below is the Code
VBA Code:
Option Explicit
Sub test()

    Dim ar As Variant
    Dim i As Long
    Dim maxdate As Date
    Dim arrdate As Long
    Dim d As Long
    
    For i = 2 To 10
   arrdate = 0
        If Cells(i, 1).Value <> "" And Len(Cells(i, 1).Value) > 5 Then
            ar = Split(Cells(i, 1).Value, "/")
                For d = LBound(ar) To UBound(ar)
                If CDate(ar(d)) > arrdate Then
                    arrdate = CDate(ar(d))
                End If
                  
                Next
                 maxdate = arrdate
                Cells(i, 2).Value = Format(maxdate, "dd/mm/yyyy")
        End If
  
    Next i

end Sub

Thanks
mg
 

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
843
Office Version
  1. 2010
Platform
  1. Windows
Hi Fluff,

Used below code giving correct output. Millions of thanks for your help ! (y) 🕺

Columns(2).NumberFormat = "m/d/yyyy"
'Columns(2).NumberFormat = "dd/mm/yyyy"


Thanks
mg
 

Some videos you may like

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Watch MrExcel Video

Forum statistics

Threads
1,123,354
Messages
5,601,139
Members
414,430
Latest member
jtdinh205

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top