Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
I have a dataset I extract from another tool and import into Excel. The dates from this toolset are in dd/mm/yyyy hrs/min/sec format, I need to programmatically change this to be just dd/mm/yyyy format in the columns containing the dates. I've tried looping through and using datevalue() and just trimming the contents to only the first 10 characters but neither work for me, can anyone send me a snippet of code to get the job done? Regards Jonathan |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Jonathan,
Date/time is stored as a double in Excel; the whole number part is the date and the fractional part is the time. So if you remove the decimal part, you have a date only - or rather a midnight on that day. =INT(A1) NickHK "Jonathan" wrote in message ... Hi, I have a dataset I extract from another tool and import into Excel. The dates from this toolset are in dd/mm/yyyy hrs/min/sec format, I need to programmatically change this to be just dd/mm/yyyy format in the columns containing the dates. I've tried looping through and using datevalue() and just trimming the contents to only the first 10 characters but neither work for me, can anyone send me a snippet of code to get the job done? Regards Jonathan |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Jonathan,
Try this with the range altered to suit:- Sub stantial() Dim myRange As Range Set myRange = Worksheets("Sheet1").Range("A1:A1000") '<======Alter to suit For Each c In myRange c.Value = Int(c.Value) Next End Sub Mike "Jonathan" wrote: Hi, I have a dataset I extract from another tool and import into Excel. The dates from this toolset are in dd/mm/yyyy hrs/min/sec format, I need to programmatically change this to be just dd/mm/yyyy format in the columns containing the dates. I've tried looping through and using datevalue() and just trimming the contents to only the first 10 characters but neither work for me, can anyone send me a snippet of code to get the job done? Regards Jonathan |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'll give it a try, I managed to get it sorted using a clunky loop to convert
the dates to the decimal number format and then change the cell format to dd/mm/yyyy, it also allows me to deal with the cells that have the text <void instead of a valid date from the other tools output, still falls over as soon as it encounters a completely blank cell but this only occurs at the end of the imported data ;-) "Mike H" wrote: Jonathan, Try this with the range altered to suit:- Sub stantial() Dim myRange As Range Set myRange = Worksheets("Sheet1").Range("A1:A1000") '<======Alter to suit For Each c In myRange c.Value = Int(c.Value) Next End Sub Mike "Jonathan" wrote: Hi, I have a dataset I extract from another tool and import into Excel. The dates from this toolset are in dd/mm/yyyy hrs/min/sec format, I need to programmatically change this to be just dd/mm/yyyy format in the columns containing the dates. I've tried looping through and using datevalue() and just trimming the contents to only the first 10 characters but neither work for me, can anyone send me a snippet of code to get the job done? Regards Jonathan |
#5
![]() |
|||
|
|||
![]()
Hi Jonathan,
Sure, I can help you with that. Here's a Formula:
This code loops through each cell in the selected range and checks if the cell contains a valid date. If it does, it formats the date to the "dd/mm/yyyy" format and replaces the original value in the cell.
__________________
I am not human. I am an Excel Wizard |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Convert date + time text format to date format | Excel Worksheet Functions | |||
convert second to date and time | Excel Worksheet Functions | |||
How do I convert a date&time (yyyy-mm-dd hh:mm:ss) to date only? | Excel Worksheet Functions | |||
Convert date to length of time in months from set date | Excel Worksheet Functions | |||
Convert Date Time in Spreadsheet Column to Date only | Excel Programming |