Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'm writing a macro in VBA
In it, I'm reading part of a long string and I want to know if that part is a date or not. Is there a way to do that? Thank you |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
It is possible if you post your string you want to get the date there... so someoneelse will helps you... -- Regards, Halim " wrote: I'm writing a macro in VBA In it, I'm reading part of a long string and I want to know if that part is a date or not. Is there a way to do that? Thank you |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
The string can be anything. That's the reason why I didn't post
anything. The string can be an actual date like 12252006 but it can also be abcde05 I'm looking for a test to figure out if the string is a date or not a date Halim wrote: Hi, It is possible if you post your string you want to get the date there... so someoneelse will helps you... -- Regards, Halim " wrote: I'm writing a macro in VBA In it, I'm reading part of a long string and I want to know if that part is a date or not. Is there a way to do that? Thank you |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
If your string is always 8 characters, you could use code like
Dim D As Date Dim S As String S = "asdd2006" On Error Resume Next Err.Clear D = DateSerial(Right(S, 4), Left(S, 2), Mid(S, 3, 2)) If Err.Number < 0 Then Debug.Print "Not a date" Else Debug.Print "Date: " & D End If If the length of the string varies, you'd have to write a bunch of Left, Mid, and Right function to break the string into multiple elements, pass those elements to DateSerial, and test the error. -- Cordially, Chip Pearson Microsoft MVP - Excel www.cpearson.com (email address is on the web site) wrote in message ups.com... The string can be anything. That's the reason why I didn't post anything. The string can be an actual date like 12252006 but it can also be abcde05 I'm looking for a test to figure out if the string is a date or not a date Halim wrote: Hi, It is possible if you post your string you want to get the date there... so someoneelse will helps you... -- Regards, Halim " wrote: I'm writing a macro in VBA In it, I'm reading part of a long string and I want to know if that part is a date or not. Is there a way to do that? Thank you |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
This seemed to work okay.
S = Format("12252006", "##/##/####") If IsDate(S) Then D = CDate(S) "Chip Pearson" wrote: If your string is always 8 characters, you could use code like Dim D As Date Dim S As String S = "asdd2006" On Error Resume Next Err.Clear D = DateSerial(Right(S, 4), Left(S, 2), Mid(S, 3, 2)) If Err.Number < 0 Then Debug.Print "Not a date" Else Debug.Print "Date: " & D End If If the length of the string varies, you'd have to write a bunch of Left, Mid, and Right function to break the string into multiple elements, pass those elements to DateSerial, and test the error. -- Cordially, Chip Pearson Microsoft MVP - Excel www.cpearson.com (email address is on the web site) wrote in message ups.com... The string can be anything. That's the reason why I didn't post anything. The string can be an actual date like 12252006 but it can also be abcde05 I'm looking for a test to figure out if the string is a date or not a date Halim wrote: Hi, It is possible if you post your string you want to get the date there... so someoneelse will helps you... -- Regards, Halim " wrote: I'm writing a macro in VBA In it, I'm reading part of a long string and I want to know if that part is a date or not. Is there a way to do that? Thank you |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Convert Date string to date format | Excel Discussion (Misc queries) | |||
Date String | Excel Discussion (Misc queries) | |||
changing a string date into a 'date' | Excel Programming | |||
Date and string help | Excel Programming | |||
Converting a string date into a Excel Date | Excel Programming |