LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Option Explicit and Date Format "dd mmm yyyy"?

Excel will still treat the string as a date, so you get the same result.
Better effort spent formatting the cell to dd mmm yyyy

--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Bob Phillips" wrote in message
...
You still need to format the result

Range("A1").Value = Format(PayDate, "dd mmm yyyy")

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Rob van Gelder" wrote in message
...
Datatype conversion is where a lot of bugs occur.

In your case, you're handing the responsibility of datatype conversion to
Excel in two places:
The Format function returns a string, which you are trying to assign to a
date.
Application.InputBox returns a string, which you are trying to assign to
a
date.

When you let the compiler (Excel) do the datatype conversion for you, you
had better be sure you know how Excel is going to do it.


Simple answer to your question:

DateFormat = Now()

PayDate = Application.InputBox("Input Pay Date to appear on
Payslips",
"DATE REQUIRED", Format(DateFormat, "dd mmm yyyy"))


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"TroyB" wrote in message
...
Hi,

I have the following extract of code requiring the user to input the

date
into a prompt and then inserted into the spreadsheet.



Sub DateTest()

dateformat = Format(Now(), "dd mmm yyyy")

PayDate = Application.InputBox("Input Pay Date to appear on Payslips",
"DATE REQUIRED", dateformat)

Range("A1").Value = PayDate

End Sub



I have recently been educated that using the "Option Explicit
Statement"
is a good way to ensure declaration of all variables and i tend to
agree
with this philosophy as the code is becoming larger (and complex!).
But
when i use the following code (including the declaration of variables),

i
can't get it to provide the date format i require, ie "dd mmm yyyy".



Option Explicit

Sub DateTest()

Dim PayDate As Date, DateFormat As Date

DateFormat = Format(Now(), "dd mmm yyyy")

PayDate = Application.InputBox("Input Pay Date to appear on

Payslips",
"DATE REQUIRED", DateFormat)

Range("A1").Value = PayDate

End Sub



Using Option Explicit, how can i provide a default input of todays date

in
"dd mmm yyyy" format and, following the user input insert the date into
the spreadsheet in the format "dd mmm yyyy"?



Thanks in advance



Boeky








 
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
2007 Need macro to auto set option buttons all to "Yes" or "No" Paula Excel Worksheet Functions 1 October 20th 09 08:07 PM
Why is the "zoom" option grayed out in "print preview?" sschreiber Excel Discussion (Misc queries) 0 November 29th 07 04:42 PM
Convert text "date" (DDMMMYY) to datetime value of YYYY-MM-DD - ho j.a. harriman Excel Discussion (Misc queries) 7 March 29th 07 01:20 AM
How to set a default paste option of "Match Destination Format" John H @ EBR Excel Discussion (Misc queries) 1 April 17th 06 09:59 PM
How To: Use Cell("Format") to return MMMM YYYY instead of D3 Kevin McCartney[_2_] Excel Programming 8 May 19th 04 01:34 AM


All times are GMT +1. The time now is 06:09 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"