![]() |
Is the string a date?
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 |
Is the string a date?
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 |
Is the string a date?
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 |
Is the string a date?
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 |
Is the string a date?
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 |
All times are GMT +1. The time now is 03:01 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com