Excel Dates how to insure the correct format when users may have different Regional settings?

leeavery3

New Member
Joined
Mar 6, 2014
Messages
16
Excel generates a .xlsx file for me through VBA from data in the existing workbook.

The generated file is uploaded to a web server and needs the date to be string in the format mm/dd/yyyy.

I though i was clever and to take into account users who have Regional setting in a different order I used the following:

textDate = Format(uploadDate, "mm/dd/yyyy")
ws1.Cells(i, 2).NumberFormat = "@"
ws1.Cells(i, 2).Value = textDate

But I not have a user that uses mm-dd-yyyy and the hyphens carry all the way through to the string. Which causes the upload file to error out.

I know i can use replace to remove hyphens for this but I want to be sure I can handle any odd setting for dates that a user may have.

Does anyone have any suggestions?
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Only for certain conditions would it make a difference. Excel sees the date as a Long Integer value and should convert the display format based on the system setting for each user automatically once the file is saved to their system. At least, that is the theory. Obviously, it does not do the complete job.
 
Upvote 0

Forum statistics

Threads
1,214,839
Messages
6,121,891
Members
449,058
Latest member
Guy Boot

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top