PC Review


Reply
Thread Tools Rate Thread

Is Cell in Date Format

 
 
dhockin@uniongas.com
Guest
Posts: n/a
 
      29th May 2007
I have a userform that has a text label that reports the calendar date/
time in the format of the activecell. All works fine when the cell has
been formated to a date format but it gets reported back in various
odd ball forms when in General format, currency, %, fraction etc.

This occurs when the cell has not yet been formated to a date
It there a way I can used to to determine if the cell is in a date
format so I can change the label in these situations

The isdate function will tell if the cell is a date but I need to know
the cell format before data is entered.

TIA

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      29th May 2007
Therre is no reason you can't format the cell before data is entered.

"(E-Mail Removed)" wrote:

> I have a userform that has a text label that reports the calendar date/
> time in the format of the activecell. All works fine when the cell has
> been formated to a date format but it gets reported back in various
> odd ball forms when in General format, currency, %, fraction etc.
>
> This occurs when the cell has not yet been formated to a date
> It there a way I can used to to determine if the cell is in a date
> format so I can change the label in these situations
>
> The isdate function will tell if the cell is a date but I need to know
> the cell format before data is entered.
>
> TIA
>
>

 
Reply With Quote
 
dhockin@uniongas.com
Guest
Posts: n/a
 
      29th May 2007

Yes Joel I could, but my form allows the user to enter the date using
one of 4 pre set formats ( dates, time or date & time) or in the the
format of the existing cell (which presumes it is a date format
already). The label shows them what it would look like, so I need to
know if it is a date format for the label. They can change after if
they want

 
Reply With Quote
 
JE McGimpsey
Guest
Posts: n/a
 
      29th May 2007
Can you not ignore format if you create the label using

Format(ActiveCell.Value, "dd mmm yyyy hh:mm:ss")

(or whatever format string you want)...


You could check the NumberFormat property for a particular format, e.g.:

If ActiveCell.NumberFormat Like "*yy*" Then
'likely a date - or use *m/d*, *d/m*, etc
Else
'Do something else
End If

In article <(E-Mail Removed)>,
(E-Mail Removed) wrote:

> I have a userform that has a text label that reports the calendar date/
> time in the format of the activecell. All works fine when the cell has
> been formated to a date format but it gets reported back in various
> odd ball forms when in General format, currency, %, fraction etc.
>
> This occurs when the cell has not yet been formated to a date
> It there a way I can used to to determine if the cell is in a date
> format so I can change the label in these situations
>
> The isdate function will tell if the cell is a date but I need to know
> the cell format before data is entered.
>
> TIA

 
Reply With Quote
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      29th May 2007
the important requirment is that it is in any date time format and not other
formats. The date format is just a number with zero equalling Jan 1, 1900
and the whole number 1 represents one day. The different time date formats
just displays this number differently.



"(E-Mail Removed)" wrote:

>
> Yes Joel I could, but my form allows the user to enter the date using
> one of 4 pre set formats ( dates, time or date & time) or in the the
> format of the existing cell (which presumes it is a date format
> already). The label shows them what it would look like, so I need to
> know if it is a date format for the label. They can change after if
> they want
>
>

 
Reply With Quote
 
=?Utf-8?B?SkxHV2hpeg==?=
Guest
Posts: n/a
 
      29th May 2007
If the user is making the input through a control on the UserForm, then you
should be able to use the value of the user input/selection to format as soon
as it has been initiated. Format(ControlValue, "d/m/yy") with ControlValue
being substituted with the appropriate code structure and the date format
being changed to what you require.

"(E-Mail Removed)" wrote:

> I have a userform that has a text label that reports the calendar date/
> time in the format of the activecell. All works fine when the cell has
> been formated to a date format but it gets reported back in various
> odd ball forms when in General format, currency, %, fraction etc.
>
> This occurs when the cell has not yet been formated to a date
> It there a way I can used to to determine if the cell is in a date
> format so I can change the label in these situations
>
> The isdate function will tell if the cell is a date but I need to know
> the cell format before data is entered.
>
> TIA
>
>

 
Reply With Quote
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      29th May 2007
If you don't want to parse the numberformat property, you could put a number
in it and check the vartype:

Activecell.Value = 1
? vartype(activecell.Value) = vbDate
True

then clearcontents the cell.

--
Regards,
Tom Ogilvy


"(E-Mail Removed)" wrote:

> I have a userform that has a text label that reports the calendar date/
> time in the format of the activecell. All works fine when the cell has
> been formated to a date format but it gets reported back in various
> odd ball forms when in General format, currency, %, fraction etc.
>
> This occurs when the cell has not yet been formated to a date
> It there a way I can used to to determine if the cell is in a date
> format so I can change the label in these situations
>
> The isdate function will tell if the cell is a date but I need to know
> the cell format before data is entered.
>
> TIA
>
>

 
Reply With Quote
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      29th May 2007
You can run the text through the datevalue function to determine if it is a
valid date

On Error Resume Next
xyz = DateValue("89:98")
If Err.Number <> 0 Then

MsgBox ("Date entered is not a valid date")
End If

On Error GoTo 0


"Tom Ogilvy" wrote:

> If you don't want to parse the numberformat property, you could put a number
> in it and check the vartype:
>
> Activecell.Value = 1
> ? vartype(activecell.Value) = vbDate
> True
>
> then clearcontents the cell.
>
> --
> Regards,
> Tom Ogilvy
>
>
> "(E-Mail Removed)" wrote:
>
> > I have a userform that has a text label that reports the calendar date/
> > time in the format of the activecell. All works fine when the cell has
> > been formated to a date format but it gets reported back in various
> > odd ball forms when in General format, currency, %, fraction etc.
> >
> > This occurs when the cell has not yet been formated to a date
> > It there a way I can used to to determine if the cell is in a date
> > format so I can change the label in these situations
> >
> > The isdate function will tell if the cell is a date but I need to know
> > the cell format before data is entered.
> >
> > TIA
> >
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
losing date format when referencing date cell on another sheet and Rich Microsoft Excel Programming 3 9th Dec 2009 01:14 AM
date format cell, to text format sunilpatel Microsoft Excel Programming 2 31st Aug 2009 03:55 PM
Re: date format cell, to text format Mishell Microsoft Excel Programming 0 31st Aug 2009 12:26 PM
How can I get date of file creation to XLS cell in date format? =?Utf-8?B?UmFkZWsgU2ltZWs=?= Microsoft Excel Worksheet Functions 3 8th Nov 2007 04:24 PM
cell format for date/time in same cell excel 2003 =?Utf-8?B?U2FuZHk=?= Microsoft Excel Worksheet Functions 1 18th Jan 2006 03:46 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:08 PM.