Consulting

Results 1 to 3 of 3

Thread: VBA is Stubbornly Interpreting 10/12 as Date

  1. #1

    VBA is Stubbornly Interpreting 10/12 as Date

    VBA is Stubbornly Interpreting 10/12 as Date
    https://social.msdn.microsoft.com/Forums/en-US/f3c6afe8-36f1-43e7-b29e-68fd1a0432e4/vba-is-stubbornly-interpreting-1012-as-date?forum=isvvba


    1. I’ve got a collection and a string variable declared



    1. I select the sizes in my listbox and then populating the myCollection collection from that list




    1. I am making sure that the currentValue is a string before I paste it in a cell




    1. Still Excel is interpreting it as date !


    1. THESE ARE SIZES NOT DATES! I don’t want Excell to format those cells for me and I think I’m making myself clear when I specifically say that this is a STRING and not a date or variant!
    2. Also - each time (despite me formatting the cells manually) Excel annoyingly changes the cell alignment to the right so I need to select the range and change it to xlLeft




    1. How do I stop excel formatting the cells for me when I don’t want it to ???


    Please help

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    Excel worksheet tries to be (too) helpful sometimes

    Try applying number format first ...

    Sheets(1).Cells(j+23,10).Numberformat="@" Sheets(1).Cells(j+23,10).Value=currentValue

    . .. or putting a single quote in front

    Sheets(1).Cells(j+23,10).Value="'" & currentValue
    Last edited by Paul_Hossler; 02-14-2019 at 10:11 AM. Reason: Bad Copy/Paste :-(
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    Format the cell as text first using .Numberformat = "@", or prefix the value with an apostrophe.
    Be as you wish to seem

Posting Permissions

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