Results 1 to 6 of 6

Thread: [RESOLVED] Day/Month problem in Excel

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    816

    Resolved [RESOLVED] Day/Month problem in Excel

    Can anyone help me here?

    Excel seems to be confusing the days and the months from what I think is very straight forward input. When you click on "new sheet" it should create a new sheet with the next montn in cell A3 (Febuary 2010) but the date it puts in is 02/01/2010. I can't find a workaround.
    Attached Files Attached Files

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Day/Month problem in Excel

    i can not read your code, but try formatting the date to suit
    sht.name = format(range("a3"), "mmmm yyyy")
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    816

    Re: Day/Month problem in Excel

    I want to put a date (1st Feb 2010) into a cell. Cell A3.
    The cell has custom format to show month and year (mmmm yyyy)

    SheetDate = DateSerial(2010, 2, 1)
    [A3].Value = SheetDate

    But for some reason A3 ends up as 2/01/2010 and displays January 2010.
    Last edited by sgrya1; Jan 16th, 2010 at 06:54 AM.

  4. #4
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Day/Month problem in Excel

    Why do you need the day part anyway if you don't want to show it?

    Set the formatting of that cell to TEXT so that it doesn't apply extra intelligence and then do:
    vb Code:
    1. SheetDate = DateSerial(2010, 2, 1)
    2. [A3].Value = Format(SheetDate,"MMMM yyyy")
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Day/Month problem in Excel

    reset the format for that cell
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    816

    Re: Day/Month problem in Excel

    Perfect.

    I thought
    [A3].Value = Format(SheetDate, "MMMM yyyy")
    would put text into the cell rather than a date. I was wrong.

    Thanks!

Posting Permissions

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



Click Here to Expand Forum to Full Width