Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default VBA Date Format

Hi,

How do you set up a cell format so that VBA accepts and reads the input as
being a date in the fomat looking like this: 12/12/04 (mm/dd/yy)?. And will
the program be able to determine things like the fact that one date is earlier
than another?
Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default VBA Date Format



Assuming the cell contains a NUMBER(dateserial)
formatted as date:

Sub foo()
Dim dtTest As Date
dtTest = CDate(Range("a1").Value2)

Range("a2") = DateSerial(Year(dtTest), Month(dtTest) + 1, Day(dtTest))
Range("a2").NumberFormat = "mm/dd/yy"
End Sub



--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


JimFor wrote :

Hi,

How do you set up a cell format so that VBA accepts and reads the
input as being a date in the fomat looking like this: 12/12/04
(mm/dd/yy)?. And will the program be able to determine things like
the fact that one date is earlier than another?
Thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default VBA Date Format

If your cell has a Date format, just assign the cell's value to a
variable. For instance:

Dim dtMy_Date As Date
dtMy_Date = Range("A1").Value

That works regardless of which date system you're using (i.e., 1900 or
1904). OTOH, if your cell is not formatted as a date the above code will
covert the value to a date, but only if it can coerce to a date (i.e.,
'11/20/2004 will work, while "hello" would give you a type mismatch),
and only in the 1900 date format.

In article ,
OSPAM (JimFor) wrote:

How do you set up a cell format so that VBA accepts and reads the
input as being a date in the fomat looking like this: 12/12/04
(mm/dd/yy)?. And will the program be able to determine things like
the fact that one date is earlier than another?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default VBA Date Format

OK. Suppose you have two sources of dates. One is user input. The other is
from an Excel file which was loaded into a worksheet. I assume I format the
cell which receives the user input using your techniques. What I now have to
do is to compare the user input date with the dates on, say, Sheet1. If a date
on Sheet1 is chronically before the date the user enters, the program does one
thing. If it is after, it does another. Can the program distinguish that? And
is it safe to say if I formatted the dates which were loaded into the sheet
using the mm/dd/yy format, the program will recognize the format. Or do I
have to set the format again when I set up the sheet.

Thanks
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default VBA Date Format

Thanks for your help.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
permanent conversion of 1904 date format to 1900 date format Jos Excel Worksheet Functions 4 November 26th 15 02:48 PM
convert serial date format to normal date format Flagworld Excel Discussion (Misc queries) 3 September 23rd 08 01:32 PM
Convert date + time text format to date format Paul Ho Excel Worksheet Functions 2 May 22nd 07 05:47 PM
code to convert date from TEXT format (03-02) to DATE format (200203) Gauthier[_2_] Excel Programming 0 September 22nd 04 03:26 PM
Change a date in text format xx.xx.20xx to a recognised date format concatenator Excel Programming 1 November 24th 03 11:33 PM


All times are GMT +1. The time now is 01:06 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"