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

Dear group,



Currently I'm building a VBA-program in access which exports a set of data
to excel.



One of the fields is a date field. This I would like to be displayed as
m/d/yyyy.



I've chosen to export the date as integer (ie. 32291 for 5/28/1988)

This since excel otherwise recognizes the input as text or swaps day and
months.

To obtain the date format on the excel sheet I use following code:

AppExcel.Range("G4:G" & Rij).NumberFormat = "m/d/yyyy"
This code has as result that the integer is put in 'd/m/yyyy' format (system
standard)



Since this is the only sheet where this format is required I do not want to
change the system settings.



Exporting the date as string gives visually the correct result however makes
it impossible to sort/calculate later on.



What is the best way to obtain the desired result?



Thanks for your reply,



D



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default VBA NumberFormat

Changing the day format to dd seems to do the trick, but you may of course
not want 01 etc.

Sub test()

Cells(1) = 37200
Cells(2) = 37200
Cells(3) = 37200

Cells(1).NumberFormat = "m/d/yyyy"
Cells(2).NumberFormat = "m/dd/yyyy"
Cells(3).NumberFormat = "dddd d mmmm yyyy"

End Sub


RBS


"Digit" wrote in message
...
Dear group,



Currently I'm building a VBA-program in access which exports a set of data
to excel.



One of the fields is a date field. This I would like to be displayed as
m/d/yyyy.



I've chosen to export the date as integer (ie. 32291 for 5/28/1988)

This since excel otherwise recognizes the input as text or swaps day and
months.

To obtain the date format on the excel sheet I use following code:

AppExcel.Range("G4:G" & Rij).NumberFormat = "m/d/yyyy"
This code has as result that the integer is put in 'd/m/yyyy' format
(system standard)



Since this is the only sheet where this format is required I do not want
to change the system settings.



Exporting the date as string gives visually the correct result however
makes it impossible to sort/calculate later on.



What is the best way to obtain the desired result?



Thanks for your reply,



D




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
.numberformat Q Aaron Excel Worksheet Functions 4 December 18th 09 02:15 AM
NumberFormat danpt Excel Discussion (Misc queries) 3 May 20th 09 10:55 PM
numberformat? Jack Sons Excel Discussion (Misc queries) 3 September 4th 07 03:44 PM
NumberFormat? alex Excel Worksheet Functions 3 March 1st 07 09:12 PM
Numberformat Syrus the Virus[_13_] Excel Programming 6 February 12th 04 02:12 PM


All times are GMT +1. The time now is 10:05 AM.

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"