Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Is there anyway to check with VBA if a date is entered as DD-MM-YY or MM-DD-YY?
How can I tell using VBA if 4-5-18 is actually 4th of May of Fifth of April? Jan |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
dpb wrote:
On 5/4/2018 2:31 AM, wrote: Is there anyway to check with VBA if a date is entered as DD-MM-YY or MM-DD-YY? How can I tell using VBA if 4-5-18 is actually 4th of May of Fifth of April? If that's all you have in isolation you can't...if there are a string of dates such that can find a value 12 in the (presumed) month field then you can make the presumption that's days and the other must be months but without some additional hints or such a specific day that can be recognized there's just insufficient data to be unequivocal. On the other hand, if the cell is properly formatted as a date, you can check the NumberFormat property: Dim tmp As Variant tmp = Split(ActiveCell.NumberFormat, "/") If UBound(tmp) 0 Then Select Case LCase(tmp(0)) Case "d", "dd", "ddd", "dddd" 'd/m/y Case "m", "mm", "mmm", "mmmm", "mmmmm" 'm/d/y Case Else 'not formatted as date End Select End If -- - Were you looking for something? - A sense of the miraculous in everyday life. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On 5/4/2018 10:55 AM, Auric__ wrote:
dpb wrote: On 5/4/2018 2:31 AM, wrote: Is there anyway to check with VBA if a date is entered as DD-MM-YY or MM-DD-YY? How can I tell using VBA if 4-5-18 is actually 4th of May of Fifth of April? If that's all you have in isolation you can't...if there are a string of dates such that can find a value 12 in the (presumed) month field then you can make the presumption that's days and the other must be months but without some additional hints or such a specific day that can be recognized there's just insufficient data to be unequivocal. On the other hand, if the cell is properly formatted as a date, you can check the NumberFormat property: Dim tmp As Variant tmp = Split(ActiveCell.NumberFormat, "/") If UBound(tmp) 0 Then Select Case LCase(tmp(0)) Case "d", "dd", "ddd", "dddd" 'd/m/y Case "m", "mm", "mmm", "mmmm", "mmmmm" 'm/d/y Case Else 'not formatted as date End Select End If But if the cell is formatted as Date and contains the data, then it will already be interpreted as whichever and all need to do is =MONTH() or =DAY() and inspect return value to know... Didn't seem as that was the OP's question/problem at least way it came across to my reading...guess we'll say if comes back to amplify. -- |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On 5/4/2018 10:55 AM, Auric__ wrote:
dpb wrote: On 5/4/2018 2:31 AM, wrote: Is there anyway to check with VBA if a date is entered as DD-MM-YY or MM-DD-YY? How can I tell using VBA if 4-5-18 is actually 4th of May of Fifth of April? If that's all you have in isolation you can't...if there are a string of dates such that can find a value 12 in the (presumed) month field then you can make the presumption that's days and the other must be months but without some additional hints or such a specific day that can be recognized there's just insufficient data to be unequivocal. On the other hand, if the cell is properly formatted as a date, you can check the NumberFormat property: Dim tmp As Variant tmp = Split(ActiveCell.NumberFormat, "/") If UBound(tmp) 0 Then Select Case LCase(tmp(0)) Case "d", "dd", "ddd", "dddd" 'd/m/y Case "m", "mm", "mmm", "mmmm", "mmmmm" 'm/d/y Case Else 'not formatted as date End Select End If But if the cell is formatted as Date and contains the data, then it will already be interpreted as whichever and all need to do is =MONTH() or =DAY() and inspect return value to know... Didn't seem as that was the OP's question/problem at least way it came across to my reading...guess we'll say if comes back to amplify. Hmm.., I rather like Auric's simplified solution since it indeed does EXACTLY what I interpret the OP is looking to accomplish. Note also that Excel uses the 'system' date format unless set otherwise for specific cells. For example, after XP the format order for d/m got switched. -- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On 5/4/2018 4:37 PM, GS wrote:
.... Hmm.., I rather like Auric's simplified solution since it indeed does EXACTLY what I interpret the OP is looking to accomplish. .... Well, it'll tell him what the cell is formatted as; whether that's what the data was when entered isn't determinable from the string which is where _I_ thought OP was coming from... :) Once it's in the cell it can be either depending on the format; is that correct or not is still indeterminate. -- |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'm sorry it has taken me so long to get back, but I have been away from my computer ever since.
I will try some of you suggestions and see if any of them solves my challenge. Thank you very much for your efforts. Jan |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
And an explanation for my problem:
The original issue was and is, that I programmatically have to change alle dates to dd-mm-yyyy format. The dates are imported from other systems, and some of these are in the format mm-dd-yyyy. Dates that are already dd-mm-yyyy shall not be converted, so I want to check the format before conversion. When the sheet is done, the data will exported to another system, who cannot check if the dates are in the right format, but expect them to be dd-mm-yyyy. Therefore I (or rather those who uses the sheet) have to maked sure all dates are formated correctly be the export. Jan |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() |
#10
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
"as GS points out, inside Excel they will have been read according to the
system default format" See my latest reply to yours regarding "DateText" vs date interpretation of text being imported with date values. -- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
#11
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
El viernes, 4 de mayo de 2018, 2:31:09 (UTC-5), escribió:
Is there anyway to check with VBA if a date is entered as DD-MM-YY or MM-DD-YY? How can I tell using VBA if 4-5-18 is actually 4th of May of Fifth of April? Jan x="4-5-18" ?format(x,"mm/dd/yyyy") 'Return 05/04/2018 ?format(x,"Long date") 'Return viernes, 4 de mayo de 2018 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Check for duplicate numbers from ones entered and anoter set | Excel Programming | |||
Dates - Need to display date one month prior to user-entered date | Excel Worksheet Functions | |||
Date subtraction -How to not show negative when 2nd date not entered | New Users to Excel | |||
Check Mark appears when a letter is entered in a field | Excel Programming | |||
Macro to check if data has been entered | Excel Programming |