Multiple dates format in same column

ryaner84

New Member
Joined
Aug 8, 2011
Messages
3
Hi guys,

i am facing a situation where i have multiple format of dates in a column. An example will be row 1-5 will be 15/1/11 and row 6-10 will be 1/15/11. however i am very sure that all these dates are supposed to be January.


is it possible for me to store a variable such as the month january stored as integer "1"

and compare the field data example
if the date is 1/15/2011 then the month is january if the date is 12/1/2011 it will rename to 1/12/2011?


Regard
Ryan Yu<!-- / message -->
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
hi i got the solution wish to share with othes

Code:
curmonth = 7
Range("A1").Select
lastrow = ActiveSheet.UsedRange.Rows.Count
    For i = 2 To lastrow
    ActiveSheet.Cells(i, 5).Select
    ActiveSheet.Cells.NumberFormat = "mm/dd/yyyy"
    
    'excelmonth is the date of the cell
    excelmonth = ActiveSheet.Cells(i, 5)
    'managed to capture the month
    extractmonth = Month(excelmonth)
    If extractmonth = curmonth Then
            ActiveSheet.Cells.NumberFormat = "mm/dd/yyyy"
            Else
    
            'to extract the date and year of excelmonth
            extractdate = Day(excelmonth)
            extractyear = Year(excelmonth)
    
            'create a new date value
            Dim newdate As Date
            newdate = DateSerial(extractyear, extractdate, extractmonth)
            'write the new date back to cell
            ActiveSheet.Cells(i, 5).Value = newdate
       
            ActiveSheet.Cells.NumberFormat = "mm/dd/yyyy"
            End If
    
    Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,524
Messages
6,179,304
Members
452,904
Latest member
CodeMasterX

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
Back
Top