+ Reply to Thread
Results 1 to 4 of 4

If statement not working properly.

  1. #1
    Registered User
    Join Date
    01-31-2013
    Location
    Denver, CO
    MS-Off Ver
    Excel 2016
    Posts
    31

    If statement not working properly.

    I am writing code to interpolate data. I want to the code recoginaze which values were given by the user and write those. I have an ifstatement in VBA to determine if the associated value was given. code:

    Please Login or Register  to view this content.
    The if statement "If cell1 = cell2 Then" doesn't recognize when cell1 = cell2. i tried adding .value which didn't work. I also tried formatting to equal the same. I added an if statement in excel to check if the two were really equal and they were. The peculiar thing, is the routine works for two of the data pairs I have but not for the third. Suggestions?

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: If statement not working properly.

    Hi

    Worked for me on my dummy up version. How about you add an example file.

    rylo

  3. #3
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: If statement not working properly.

    I reckon you're probably dealing with very small decimal differences-try rounding the values to a set number of decimal places before you compare them
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  4. #4
    Registered User
    Join Date
    01-31-2013
    Location
    Denver, CO
    MS-Off Ver
    Excel 2016
    Posts
    31

    Re: If statement not working properly.

    Thanks for the replies. Turns out it was a rounding error. excel stores 15 decimal places while VBA stores much more than that. After rounding the answer, I was able to get the program to run. Thanks for the help.

+ 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