+ Reply to Thread
Results 1 to 44 of 44

Date Format when writing back to Spreadsheet

  1. #1
    Forum Contributor
    Join Date
    03-31-2009
    Location
    Dartford
    MS-Off Ver
    Excel 2007
    Posts
    237

    Date Format when writing back to Spreadsheet

    I though I had solved this problem but I have not.

    I have a spreadsheet and a user form, I input data through the user form and it writes the dats to the spreadsheet, my problem is that everything is set to UK format dd/mm/yyy but when the form writes the data back to the spreadsheet it displays it on the spreadsheet as US formatt mm/dd/yyy even throguh it is formatted as UK. Please can someone help me, I have now idea what to do.

    A copy of the database is attached.

    Shazz.
    xx
    Last edited by Shazz; 02-09-2012 at 11:02 AM. Reason: Solved

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Date Format when writing back to Spreadsheet

    We seem to be doing all the work here.

    I answered a question last night about the form overwriting formulas which added the dates.

    Are you using these formulas or using dates input with the form?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Contributor
    Join Date
    03-31-2009
    Location
    Dartford
    MS-Off Ver
    Excel 2007
    Posts
    237

    Re: Date Format when writing back to Spreadsheet

    I have not mentioned Formulas in my post, What I have a problem with is the date format writing back to the spreadsheet in US not UK.

    Shazz

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Date Format when writing back to Spreadsheet

    Adapt this code

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: Date Format when writing back to Spreadsheet

    Shazz

    When you write 'dates' (which are really text eg because they are sourced from a textbox) back into an Excel cell, it is best to convert to a true date first, otherwise Excel usually goes with MDY date formatting.

    Hence, in your code when you have a line like:

    Please Login or Register  to view this content.
    and this is writing a date out, then you should use DateValue to wrpa the TextBox value (DateValue will use your regional settings to determine how to convert a string date to a true date):

    Please Login or Register  to view this content.
    Note: I just chose an exmaple line from your code - I have no idea if that line was writing a date back to the sheet (so you just need to modify the lines that write dates).

  6. #6
    Forum Contributor
    Join Date
    03-31-2009
    Location
    Dartford
    MS-Off Ver
    Excel 2007
    Posts
    237

    Re: Date Format when writing back to Spreadsheet

    Hi FireFly,

    I have amended my code, (See below but it shows an error (by Highlighting yellow) at (SelRow, 9)

    Please Login or Register  to view this content.
    Can you notice if I have done something wrong.

    Shazz

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Date Format when writing back to Spreadsheet

    Use DateSerial & NumberFormat as I have shown in my code, in my opinion it's the most reliable method.

    What error is reported, have you a date in the TextBox?

  8. #8
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: Date Format when writing back to Spreadsheet

    What is your error when the code fails (number and description please)? Also, what does TextBox9 contain (what is its value)?

    Roy, regarding your code - you have already converted to a date using CDate (which will use your Regional Settings) so using DateSerial as well seems like unnecessary overhead. Both our suggestions are equivalent.

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Date Format when writing back to Spreadsheet

    Dates are so temperamental I don't take any risks.

  10. #10
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Date Format when writing back to Spreadsheet

    FWIW I used to use DateSerial but changed to DateValue a while back and haven't run into any problems that I can think of.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  11. #11
    Forum Contributor
    Join Date
    03-31-2009
    Location
    Dartford
    MS-Off Ver
    Excel 2007
    Posts
    237

    Re: Date Format when writing back to Spreadsheet

    Hi,

    It does not give what the error is, it just highlights the row in yellow.

    Shazz

  12. #12
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Date Format when writing back to Spreadsheet

    You mean you get no error message at all? If so, what happens if you simply press f5 when the code stops?
    Good luck.

  13. #13
    Forum Contributor
    Join Date
    03-31-2009
    Location
    Dartford
    MS-Off Ver
    Excel 2007
    Posts
    237

    Re: Date Format when writing back to Spreadsheet

    It come up "Run Type Error '13' Type Mismatch.

    Shazz

  14. #14
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Date Format when writing back to Spreadsheet

    Then whatever is in that textbox is not a date.

  15. #15
    Forum Contributor
    Join Date
    03-31-2009
    Location
    Dartford
    MS-Off Ver
    Excel 2007
    Posts
    237

    Re: Date Format when writing back to Spreadsheet

    It is definately at Date, it brings this error up as soon as I try to open the Data Form.

    Sorry I am such a pain!!!

    Shazz

  16. #16
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Date Format when writing back to Spreadsheet

    If it happens as soon as you open the form, why is the form trying to save data?

  17. #17
    Forum Contributor
    Join Date
    03-31-2009
    Location
    Dartford
    MS-Off Ver
    Excel 2007
    Posts
    237

    Re: Date Format when writing back to Spreadsheet

    The form is set up to show the data from the spreadsheet, that's all I can think of, dont worry I am sorry to be such a pain, I will try and figurer it out by myself.

    Shazz

  18. #18
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Date Format when writing back to Spreadsheet

    Post the current file.
    I suspect you are setting the row number which is triggering the save automatically, in which case you need an escape variable that allows you to change controls without triggering their events.

  19. #19
    Forum Contributor
    Join Date
    03-31-2009
    Location
    Dartford
    MS-Off Ver
    Excel 2007
    Posts
    237

    Re: Date Format when writing back to Spreadsheet

    Ok, I think I know the problem but I do not know how to fix it, If there is not entry ie date in the date fields it is showing the run time error. the only prolems is not all the date fields will be completed, do you know how I get around this.

    Also when entering the date in it is showing as US format on the spreadsheet even though I am setting it to Uk dd/mm/yy. do you have any suggestions??

    Shazz
    Last edited by Shazz; 02-09-2012 at 11:03 AM.

  20. #20
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Date Format when writing back to Spreadsheet

    So it wasn't a valid date then!

    Add this function to the code
    Please Login or Register  to view this content.
    and then use
    Please Login or Register  to view this content.
    and so on.

  21. #21
    Forum Contributor
    Join Date
    03-31-2009
    Location
    Dartford
    MS-Off Ver
    Excel 2007
    Posts
    237

    Re: Date Format when writing back to Spreadsheet

    Sorry to sound thick as always, please can you tell me exactly where the first part of the code above needs to go?

    Will that also sort out the problem with the date format changing??

    Shazz
    xx

  22. #22
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Date Format when writing back to Spreadsheet

    In the userform, below your existing routines.

    It should do.

  23. #23
    Forum Contributor
    Join Date
    03-31-2009
    Location
    Dartford
    MS-Off Ver
    Excel 2007
    Posts
    237

    Re: Date Format when writing back to Spreadsheet

    I have done and now I am getting the below error:

    Compile Error:
    Ambiguous Date Detected: Getdate
    Please Login or Register  to view this content.
    See attachment, would you be a complete honey and maybe change what ever I have done wrong, that way I will not have to keep bothering you anymore.

    Shazz
    xx
    Last edited by Shazz; 02-09-2012 at 11:04 AM. Reason: Added attachment

  24. #24
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Date Format when writing back to Spreadsheet

    You have pasted the function in twice - remove one version.

    Note: some of your date columns are formatted to display in US date format, which I suspect is where your confusion lies.

    I cannot attach the revised file (due to forum gremlins - i.e. the buffoons who program it) so you will have to make the changes yourself, I am afraid.

  25. #25
    Forum Contributor
    Join Date
    03-31-2009
    Location
    Dartford
    MS-Off Ver
    Excel 2007
    Posts
    237

    Re: Date Format when writing back to Spreadsheet

    I just don't understand why it is still showing as us format onthe spreadsheet, I have set every date cell to UK format but for some reason the when i add the data through the form is changes the spreadsheet.

    Help!!!!

    Shazz
    xx

  26. #26
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Date Format when writing back to Spreadsheet

    I still cannot attach, but in the file you posted a lot of cells were formatted as US date.

  27. #27
    Forum Contributor
    Join Date
    03-31-2009
    Location
    Dartford
    MS-Off Ver
    Excel 2007
    Posts
    237

    Re: Date Format when writing back to Spreadsheet

    I have changed all the dates to UK and it has not made a differnce at all?

    Why can you not post then?

    Shazz

  28. #28
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Date Format when writing back to Spreadsheet

    Because I simply get an error page every time I attempt it. Not the first time - every time they fix it, they break it again later.

    Your file works for me - are you sure your regional settings are not US on your computer?

  29. #29
    Forum Contributor
    Join Date
    03-31-2009
    Location
    Dartford
    MS-Off Ver
    Excel 2007
    Posts
    237

    Re: Date Format when writing back to Spreadsheet

    I don't think so, all my other spreadsheets are fine where the date is concerned, How would I check that?

    I really am so sorry to be such a pain, this is the last thing I need to sort out and it really is bugging me.

    If I PM'ed you my email would you send it through?

    Shazz
    xx
    Last edited by Shazz; 02-09-2012 at 07:57 AM. Reason: add text

  30. #30
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Date Format when writing back to Spreadsheet

    Check under Control panel - regional options.

    Is it all the dates from the form that convert, or just some?

  31. #31
    Forum Contributor
    Join Date
    03-31-2009
    Location
    Dartford
    MS-Off Ver
    Excel 2007
    Posts
    237

    Re: Date Format when writing back to Spreadsheet

    The Regional Settings are set to UK, It is all the Dates and if I put a date in the spreadsheet and it does show as UK Format, it then shows as US format in the Form????

    Shazz
    xx

  32. #32
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Date Format when writing back to Spreadsheet

    I still cannot attach the file, so if you PM me an email address, I will send you the revised copy, which works for me.

  33. #33
    Forum Contributor
    Join Date
    03-31-2009
    Location
    Dartford
    MS-Off Ver
    Excel 2007
    Posts
    237

    Re: Date Format when writing back to Spreadsheet

    In the Text Box I see 07/05/2012.

    Sorry to be a pain, I am going to delete all the date text boxes and re do them to see if that makes any difference, but if not, can you show me how to show the date in the user form as 1st February 2012 format, at least then even though it shows as US format it is still obvious what the date is.

    Shazz
    xx

  34. #34
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Date Format when writing back to Spreadsheet

    If you format the cells in the sheet as dd mmm yyyy then you can load them into the form using the Text property of the cell rather than the Value property.

  35. #35
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Date Format when writing back to Spreadsheet

    One last thought - in the Regional settings in control panel, what is your Short Date format set to?

  36. #36
    Forum Contributor
    Join Date
    03-31-2009
    Location
    Dartford
    MS-Off Ver
    Excel 2007
    Posts
    237

    Re: Date Format when writing back to Spreadsheet

    it is set to 09/02/2012.

    I also asked my friend to open it up on a completely diffrent computer and he also said it shows in US format on the Form.

    If you format the cells in the sheet as dd mmm yyyy then you can load them into the form using the Text property of the cell rather than the Value property.
    How do I do this?

    Shazz

  37. #37
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Date Format when writing back to Spreadsheet

    Pretty much exactly as I said. Change the format of the cells (select, then Ctrl+1) to dd mmm yyyy and then where your LoadData code refers to .Value use .Text instead.

    If anyone else is still following this, I would be intrigued to know if they see the dates in UK or US format.

  38. #38
    Forum Contributor
    Join Date
    03-31-2009
    Location
    Dartford
    MS-Off Ver
    Excel 2007
    Posts
    237

    Re: Date Format when writing back to Spreadsheet

    Do mean every single line even if not a date?

    TextBox9.Text = .Cells(SelRow, 9).Text
    Like this?

    Shazz

  39. #39
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Date Format when writing back to Spreadsheet

    No - only the date ones are required (unless you want to put formatted values in any other textboxes).

  40. #40
    Forum Contributor
    Join Date
    03-31-2009
    Location
    Dartford
    MS-Off Ver
    Excel 2007
    Posts
    237

    Re: Date Format when writing back to Spreadsheet

    One Question, is the below code correct for the Load Data as non of the text boxes are refered to as Dates? I have never be told to change this. If so what do I change it to??

    Please Login or Register  to view this content.

  41. #41
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Date Format when writing back to Spreadsheet

    One other long shot. Remove the code from the Exit events of your textboxes that formats the contents as a date. It should not be necessary.

  42. #42
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Date Format when writing back to Spreadsheet

    All the date textboxes need to loaded the same way you have done textbox9

  43. #43
    Forum Contributor
    Join Date
    03-31-2009
    Location
    Dartford
    MS-Off Ver
    Excel 2007
    Posts
    237

    Re: Date Format when writing back to Spreadsheet

    Hoorah, It is finally working correctly.

    Thanks you for all your help and persaveriance, not sure if I spelt that correctly lol

    Shazz
    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

  44. #44
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Date Format when writing back to Spreadsheet

    Glad we got there in the end!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1