+ Reply to Thread
Results 1 to 8 of 8

VBA code gives wrong result

  1. #1
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    882

    VBA code gives wrong result

    Hi guys

    The following code doesn't give me the right result. If I type the following values in comboboxes:

    combobox3=6
    combobox4=4
    combobox5=2012

    Then the following code displays "Normal" but it should be "Post Dated".
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Can anyone please help me out in this.

    Thanks

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: VBA code gives wrong result

    My first guess is that it's treating TextBox1.Value as a string rather than as a date, so assigning it a value of 0 for the numeric comparison.

  3. #3
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    882

    Re: VBA code gives wrong result

    Thanks Andrew-R, so what changes do I need to make to get it working.

  4. #4
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    882

    Re: VBA code gives wrong result

    Thanks OnErrorGoTo0 , It works perfetcly fine ow.

  5. #5
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: VBA code gives wrong result

    Quote Originally Posted by OnErrorGoto0 View Post
    I think you're right about the cause but all strings are treated as greater than any number, hence the result.
    Once again I learn something new on here. Thanks OnError.

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: VBA code gives wrong result

    ... and further to the answers you've been given your message box was always going to show 'Normal' since you'd applied a literal to it rather than the status variable.

    Regards
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  7. #7
    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: VBA code gives wrong result

    Oh yeah!
    Good luck.

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

    Re: VBA code gives wrong result

    There's an example of comboboxes being used for dates here
    Hope that helps.

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

    Free DataBaseForm example

+ 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