+ Reply to Thread
Results 1 to 5 of 5

Macro works correctly from VBE but not from button

  1. #1
    Forum Contributor
    Join Date
    06-15-2011
    Location
    Chester, England
    MS-Off Ver
    Excel 2013
    Posts
    117

    Macro works correctly from VBE but not from button

    In the attached, the macro works correctly when run from the VBE, but when running from a button, the dates end up in American format and some of the dates are unaffected.

    Any idea why this is happening?

    Thanks in advance.
    Attached Files Attached Files

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Macro works correctly from VBE but not from button

    What exactly are you trying to accomplish?
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro works correctly from VBE but not from button

    The problem is you're not taking into account the fact that the time strings in V:X are in the wrong format to start with. To turn them from strings into Date values you have to fix the data, too. Try this, edit the date format to the one you want:

    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Forum Contributor
    Join Date
    06-15-2011
    Location
    Chester, England
    MS-Off Ver
    Excel 2013
    Posts
    117

    Re: Macro works correctly from VBE but not from button

    I was trying to avoid several lines of code by using one - mine works when it is run from the VBE.

    Please Login or Register  to view this content.
    I still don't understand why this same line of code doesn't work from a button, but many thanks for providing a solution that works - it's much appreciated.

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro works correctly from VBE but not from button

    I tried to explain it. Your macro DOES apply the command to the range of cells as given, it just doesn't "work". You haven't dealt with the fact that the original strings are simply NOT in a format that fixes the dates correctly.

    When I run your original macro many of the cells DO change to true dates, but they were changing to the wrong dates. So in truth, it wasn't working on ANY of the cells. The ones it converted were converted incorrectly, and other cells it simply didn't work on at all.

    My macro "extracts" the year, month and day values from the string, then the time value, then reconstructs it all into an Excel timestamp you can then format to your liking.


    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

+ 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