Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Date in YY/MM/DD format

I have a general formated cell with the following in:-

DIN 060416 (the numbers change day to day of course)

In a Macro I need to remove the "DIN" part which I can do, but as soon as I
do this it alters the format to number and shows it 60416 which if you try
and date format is completely wrong.

I need it to be 06/04/16. Any help would be much appriciated and as you can
prob tell I am rubbish on Excel ;) Alastair.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Date in YY/MM/DD format

You can probably adapt this for your needs

Dim tmp As String
With ActiveCell
tmp = Trim(Replace(.Value, "DIN", ""))
.Value = DateSerial(Right(tmp, 2), Mid(tmp, 3, 2), Left(tmp, 2))
End With


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Alastair79" wrote in message
...
I have a general formated cell with the following in:-

DIN 060416 (the numbers change day to day of course)

In a Macro I need to remove the "DIN" part which I can do, but as soon as

I
do this it alters the format to number and shows it 60416 which if you try
and date format is completely wrong.

I need it to be 06/04/16. Any help would be much appriciated and as you

can
prob tell I am rubbish on Excel ;) Alastair.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Date in YY/MM/DD format

Bob, this worked a treat after I swapped the Left and Right part around.
Thanks alot, Alastair.

"Bob Phillips" wrote:

You can probably adapt this for your needs

Dim tmp As String
With ActiveCell
tmp = Trim(Replace(.Value, "DIN", ""))
.Value = DateSerial(Right(tmp, 2), Mid(tmp, 3, 2), Left(tmp, 2))
End With


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Alastair79" wrote in message
...
I have a general formated cell with the following in:-

DIN 060416 (the numbers change day to day of course)

In a Macro I need to remove the "DIN" part which I can do, but as soon as

I
do this it alters the format to number and shows it 60416 which if you try
and date format is completely wrong.

I need it to be 06/04/16. Any help would be much appriciated and as you

can
prob tell I am rubbish on Excel ;) Alastair.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Date in YY/MM/DD format

Is this one column?

If yes, record a macro when you select that column.
choose fixed width
draw a line right before the first digit (after the "din ")
Choose ignore (Do not import) the first field
choose ymd (or myd???) for the date portion

And plop it down directly in the original location.

Alastair79 wrote:

I have a general formated cell with the following in:-

DIN 060416 (the numbers change day to day of course)

In a Macro I need to remove the "DIN" part which I can do, but as soon as I
do this it alters the format to number and shows it 60416 which if you try
and date format is completely wrong.

I need it to be 06/04/16. Any help would be much appriciated and as you can
prob tell I am rubbish on Excel ;) Alastair.


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default Date in YY/MM/DD format

=DATE(MID(A1,LEN(A1)-5,2),MID(A1,LEN(A1)-3,2),RIGHT(A1,2))

--
Kind regards,

Niek Otten

"Alastair79" wrote in message ...
|I have a general formated cell with the following in:-
|
| DIN 060416 (the numbers change day to day of course)
|
| In a Macro I need to remove the "DIN" part which I can do, but as soon as I
| do this it alters the format to number and shows it 60416 which if you try
| and date format is completely wrong.
|
| I need it to be 06/04/16. Any help would be much appriciated and as you can
| prob tell I am rubbish on Excel ;) Alastair.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Date in YY/MM/DD format

Select the cells and run this macro.

Sub abd()
Dim dt As Date
Dim s As String, y As String
Dim m As String, d As String
For Each cell In Selection
s = Trim(cell)
If UCase(Left(cell, 3)) = "DIN" Then
s = Replace(UCase(s), "DIN ", "")
s = Replace(UCase(s), "DIN", "")
y = Mid(s, 1, 2)
m = Mid(s, 3, 2)
d = Mid(s, 5, 2)
dt = DateValue(m & "/" & d & "/" & y)
cell.Value = dt
cell.NumberFormat = "yy/mm/dd"
End If
Next
End Sub

--
Regards,
Tom Ogilvy


"Alastair79" wrote:

I have a general formated cell with the following in:-

DIN 060416 (the numbers change day to day of course)

In a Macro I need to remove the "DIN" part which I can do, but as soon as I
do this it alters the format to number and shows it 60416 which if you try
and date format is completely wrong.

I need it to be 06/04/16. Any help would be much appriciated and as you can
prob tell I am rubbish on Excel ;) Alastair.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
permanent conversion of 1904 date format to 1900 date format Jos Excel Worksheet Functions 4 November 26th 15 02:48 PM
How do I convert dd/mm/yy date format to yyddd Julian date format itzy bitzy[_2_] Excel Worksheet Functions 8 December 11th 09 03:20 AM
change date format dd/mm/yyyy to Julian date format? itzy bitzy Excel Worksheet Functions 1 December 8th 09 07:42 PM
code to convert date from TEXT format (03-02) to DATE format (200203) Gauthier[_2_] Excel Programming 0 September 22nd 04 03:26 PM
Change a date in text format xx.xx.20xx to a recognised date format concatenator Excel Programming 1 November 24th 03 11:33 PM


All times are GMT +1. The time now is 04:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"