#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default Date Format

I have created a user form which automatically enters the current date by
using the following code in the UserForm Initialize.
txtDate.Value = Now()
When the information is put in the spreadsheet it shows the date in one cell
like this:
4/9/2006 19:33
I would like to format the date in vba within the form so that it returns
only the month and year, leaving out the day and time. I don't want to do
this by formatting the column in the worksheet because I will need to
manipulate the date in formulas.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default Date Format

You can instead use:
txtDate.Value = Date

However, as long as you want the value to be a "date", there is no way to
get rid of the "day". (Otherwise, it's not a date! A date contains "year",
"month", and "day", three components.) You can at most use cell format to
display only the month and year.

There should be other approaches which can be used in the "formulas" you
mentioned. Maybe you can share with us and I'm sure someone can help.

Regards,
Edwin Tam

http://www.vonixx.com


"juliejg1" wrote:

I have created a user form which automatically enters the current date by
using the following code in the UserForm Initialize.
txtDate.Value = Now()
When the information is put in the spreadsheet it shows the date in one cell
like this:
4/9/2006 19:33
I would like to format the date in vba within the form so that it returns
only the month and year, leaving out the day and time. I don't want to do
this by formatting the column in the worksheet because I will need to
manipulate the date in formulas.

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

txtDate.value = format(now(),"mmm yyyy")

--
Regards,
Tom Ogilvy


"juliejg1" wrote:

I have created a user form which automatically enters the current date by
using the following code in the UserForm Initialize.
txtDate.Value = Now()
When the information is put in the spreadsheet it shows the date in one cell
like this:
4/9/2006 19:33
I would like to format the date in vba within the form so that it returns
only the month and year, leaving out the day and time. I don't want to do
this by formatting the column in the worksheet because I will need to
manipulate the date in formulas.

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

Thanks!

"Tom Ogilvy" wrote:

txtDate.value = format(now(),"mmm yyyy")

--
Regards,
Tom Ogilvy


"juliejg1" wrote:

I have created a user form which automatically enters the current date by
using the following code in the UserForm Initialize.
txtDate.Value = Now()
When the information is put in the spreadsheet it shows the date in one cell
like this:
4/9/2006 19:33
I would like to format the date in vba within the form so that it returns
only the month and year, leaving out the day and time. I don't want to do
this by formatting the column in the worksheet because I will need to
manipulate the date in formulas.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default Date Format

Thanks1

"Edwin Tam" wrote:

You can instead use:
txtDate.Value = Date

However, as long as you want the value to be a "date", there is no way to
get rid of the "day". (Otherwise, it's not a date! A date contains "year",
"month", and "day", three components.) You can at most use cell format to
display only the month and year.

There should be other approaches which can be used in the "formulas" you
mentioned. Maybe you can share with us and I'm sure someone can help.

Regards,
Edwin Tam

http://www.vonixx.com


"juliejg1" wrote:

I have created a user form which automatically enters the current date by
using the following code in the UserForm Initialize.
txtDate.Value = Now()
When the information is put in the spreadsheet it shows the date in one cell
like this:
4/9/2006 19:33
I would like to format the date in vba within the form so that it returns
only the month and year, leaving out the day and time. I don't want to do
this by formatting the column in the worksheet because I will need to
manipulate the date in formulas.



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

But note that you still cannot actually get rid of the "day". By default
Excel just put the 1st day of the month for you. For example, 1st of Apr
2006. There is absolutely no way you can get rid of the day. The effect of
that statement is identical to formatting the cell, which you specifically
mentioned you don't want to do.

Regards,
Edwin Tam

http://www.vonixx.com


"juliejg1" wrote:

Thanks!

"Tom Ogilvy" wrote:

txtDate.value = format(now(),"mmm yyyy")

--
Regards,
Tom Ogilvy


"juliejg1" wrote:

I have created a user form which automatically enters the current date by
using the following code in the UserForm Initialize.
txtDate.Value = Now()
When the information is put in the spreadsheet it shows the date in one cell
like this:
4/9/2006 19:33
I would like to format the date in vba within the form so that it returns
only the month and year, leaving out the day and time. I don't want to do
this by formatting the column in the worksheet because I will need to
manipulate the date in formulas.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Date Format

Actually, format returns a string, so what you see is what you get. There is
no day associated with it as it is no longer a date (if I recall
correctly)...
--
HTH...

Jim Thomlinson


"Edwin Tam" wrote:

But note that you still cannot actually get rid of the "day". By default
Excel just put the 1st day of the month for you. For example, 1st of Apr
2006. There is absolutely no way you can get rid of the day. The effect of
that statement is identical to formatting the cell, which you specifically
mentioned you don't want to do.

Regards,
Edwin Tam

http://www.vonixx.com


"juliejg1" wrote:

Thanks!

"Tom Ogilvy" wrote:

txtDate.value = format(now(),"mmm yyyy")

--
Regards,
Tom Ogilvy


"juliejg1" wrote:

I have created a user form which automatically enters the current date by
using the following code in the UserForm Initialize.
txtDate.Value = Now()
When the information is put in the spreadsheet it shows the date in one cell
like this:
4/9/2006 19:33
I would like to format the date in vba within the form so that it returns
only the month and year, leaving out the day and time. I don't want to do
this by formatting the column in the worksheet because I will need to
manipulate the date in formulas.

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default Date Format

In the original question, the sentence "When the information is put in the
spreadsheet..." implied that the value is to be placed in a cell in the
worksheet.

Therefore, if you try to experiment in the immediate window,
selection.value = format(now(),"mmm yyyy")

You can see that Excel actually put the 1st of April 2006 into the cell. It
is not a string at all, and the statement does not at all instruct Excel to
return a string.

Regards,
Edwin Tam

http://www.vonixx.com



"Jim Thomlinson" wrote:

Actually, format returns a string, so what you see is what you get. There is
no day associated with it as it is no longer a date (if I recall
correctly)...
--
HTH...

Jim Thomlinson


"Edwin Tam" wrote:

But note that you still cannot actually get rid of the "day". By default
Excel just put the 1st day of the month for you. For example, 1st of Apr
2006. There is absolutely no way you can get rid of the day. The effect of
that statement is identical to formatting the cell, which you specifically
mentioned you don't want to do.

Regards,
Edwin Tam

http://www.vonixx.com


"juliejg1" wrote:

Thanks!

"Tom Ogilvy" wrote:

txtDate.value = format(now(),"mmm yyyy")

--
Regards,
Tom Ogilvy


"juliejg1" wrote:

I have created a user form which automatically enters the current date by
using the following code in the UserForm Initialize.
txtDate.Value = Now()
When the information is put in the spreadsheet it shows the date in one cell
like this:
4/9/2006 19:33
I would like to format the date in vba within the form so that it returns
only the month and year, leaving out the day and time. I don't want to do
this by formatting the column in the worksheet because I will need to
manipulate the date in formulas.

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
How do I convert dd/mm/yy date format to yyddd Julian date format itzy bitzy[_2_] Excel Worksheet Functions 8 December 11th 09 03:20 AM
Excel 2000 date format cannot be set to Australian date format Brian Jones Excel Discussion (Misc queries) 1 March 30th 05 06:03 AM
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 12:42 PM.

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

About Us

"It's about Microsoft Excel"