Dates & Formatting

aeddipa

Active Member
Joined
Jun 1, 2009
Messages
337
I have data that I extract from a website which has several hundred rows of data. Most of the dates look fine, but there are several at the end, which are different from the others.

When I do a =TYPE Function I find the last few rows that the problem is occuring in are number while the rest is text. It also occurs whenever there are not 10 digits in the date Ex. 6/10/2009. As we can see there is no 0 in front of the 6. It should read 06/10/2009, but isn't and thus my VBA code is having difficulties along with the formatting being off.

When I do a format of the dates to "dd/mm/yyyy" so that I may present all of the data in one unique format, the data switches. So for example, a date that is 10/01/2009 is formatting to 01/10/2009 which is incorrect. Is there any way that I could potentially change the type of any number to text format and then switch to "dd/mm/yyyy" format without it changing the month on me. Perhaps, based on the data in the previous rows if a majority of the month's is "10" then it will place 10 in the mm and not change to "01" as in the example.

Here is some sample data:

Oct KY Detail

<TABLE style="PADDING-RIGHT: 2pt; PADDING-LEFT: 2pt; FONT-SIZE: 11pt; FONT-FAMILY: Calibri,Arial; BACKGROUND-COLOR: #ffffff" cellSpacing=0 cellPadding=0 border=1><COLGROUP><COL style="FONT-WEIGHT: bold; WIDTH: 30px"><COL style="WIDTH: 105px"><COL style="WIDTH: 64px"></COLGROUP><TBODY><TR style="FONT-WEIGHT: bold; FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center"><TD> </TD><TD>A</TD><TD>B</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">315</TD><TD style="TEXT-ALIGN: right">15/10/2009</TD><TD>Sale</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">316</TD><TD style="TEXT-ALIGN: right">15/10/2009</TD><TD>Sale</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">317</TD><TD style="TEXT-ALIGN: right">9/10/2009</TD><TD>Accrued Interest</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">318</TD><TD style="TEXT-ALIGN: right">9/10/2009</TD><TD>Income</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">319</TD><TD style="TEXT-ALIGN: right">8/10/2009</TD><TD>Accrued Interest</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">320</TD><TD style="TEXT-ALIGN: right">8/10/2009</TD><TD>Income</TD></TR></TBODY></TABLE>


<TABLE style="PADDING-RIGHT: 2pt; PADDING-LEFT: 2pt; FONT-SIZE: 11pt; FONT-FAMILY: Calibri,Arial; BACKGROUND-COLOR: #ffffff" cellSpacing=0 cellPadding=0 border=1><COLGROUP><COL style="FONT-WEIGHT: bold; WIDTH: 30px"><COL style="WIDTH: 75px"><COL style="WIDTH: 110px"></COLGROUP><TBODY><TR style="FONT-WEIGHT: bold; FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center"><TD> </TD><TD>A</TD><TD>B</TD></TR><TR style="HEIGHT: 55px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">1</TD><TD style="TEXT-ALIGN: right">10/09/2009</TD><TD>Accrued Interest</TD></TR><TR style="HEIGHT: 55px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">2</TD><TD style="TEXT-ALIGN: right">10/09/2009</TD><TD>Income</TD></TR><TR style="HEIGHT: 55px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">3</TD><TD style="TEXT-ALIGN: right">10/08/2009</TD><TD>Accrued Interest</TD></TR><TR style="HEIGHT: 55px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">4</TD><TD style="TEXT-ALIGN: right">10/08/2009</TD><TD>Income</TD></TR></TBODY></TABLE>

The first data set has the first two rows in the format they should be. This is for October data. However, the next 4 rows are slightly different. They exclude the 0 before the date and they are =TYPE (1) number. When my VBA runs, the date switches to the month becoming 09/10 or 08/10. This is not what I want.

Is there any way that I can counteract this from occurring? I cannot control the data that I download from a bank however I need it in a specific date format of "dd/mm/yyyy" so that I may import it into my accounting system.

If you need the VBA code to help piece this together, just let me know.

Thanks in advance!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,214,875
Messages
6,122,044
Members
449,063
Latest member
ak94

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