+ Reply to Thread
Results 1 to 3 of 3

If condition not met, but runs the statement.

Hybrid View

  1. #1
    Registered User
    Join Date
    07-21-2015
    Location
    Monterrey, México
    MS-Off Ver
    MAC 2011
    Posts
    6

    If condition not met, but runs the statement.

    Hi Excel Forum population,

    I am writing a simple code in which I want to get some values when a certain condition is met. The problem is that the statements are not met but the procedure is being run. I attach the code:

    i = Per
    j = 10
    ReDim SMTM(1 To Per), ISR(1 To Per), Lim(1 To j), LI(1 To j), LS(1 To j), CF(1 To j), P(1 To j) As Variant
        For i = 1 To Per
            SRI = 1
            While SRI <> SMT(i)
                Asim = SMT(i) - SRI
                
                If Round(Asim, 2) <= Round(1.9758, 2) Then
                
                j = 1
                LI(j) = 0.2328
                LS(j) = 1.9758
                CF(j) = 9.52
                P(j) = 0.064
                Lim(j) = 1
                End If
                
                
                If Round(1.9758, 2) < Round(Asim, 2) < Round(3.4722, 2) Then
                j = 2
                LI(j) = 1.9758
                LS(j) = 3.4722
                CF(j) = 247.24
                P(j) = 0.1088
                Lim(j) = 2
                End If
                
                If Round(3.4722,2) < Round(Asim,2) < Round(4.0363,2) Then
                j = 3
                LI(j) = 3.4722
                LS(j) = 4.0363
                CF(j) = 247.24
                P(j) = 0.1088
                Lim(j) = 3
                End If
                
                If Round(4.0363, 2) < Round(Asim, 2) < Round(4.8325, 2) Then
                j = 4
                LI(j) = 4.0363
                LS(j) = 4.8325
                CF(j) = 786.54
                P(j) = 0.1792
                Lim(j) = 4
                End If
                
                If Round(4.8325,2) < Round(Asim,2) <= Round(9.7466,2) Then
                j = 5
                LI(j) = 4.8325
                LS(j) = 9.7466
                CF(j) = 1090.61
                P(j) = 0.2136
                Lim(j) = 5
                End If
                
                If Round(9.7466, 2) < Round(Asim, 2) <= Round(15.3619, 2) Then
                j = 6
                LI(j) = 9.7466
                LS(j) = 15.3619
                CF(j) = 3327.42
                P(j) = 0.2352
                Lim(j) = 6
                End If
                
                If (Round(15.3619, 2)) <(Round(Asim, 2)) <=(Round(29.3284, 2)) Then
                j = 7
                LI(j) = 15.3619
                LS(j) = 29.3284
                CF(j) = 6141.95
                P(j) = 0.3
                Lim(j) = 7
                End If
                
                If Round(29.3294, 2) < Round(Asim, 2) <= Round(39.1045, 2) Then
                j = 8
                LI(j) = 29.3294
                LS(j) = 39.1045
                CF(j) = 15070.9
                P(j) = 0.32
                Lim(j) = 8
                End If
                
                If Round(39.1045, 2) < Round(Asim, 2) <= Round(117.3136, 2) Then
                j = 9
                LI(j) = 39.1045
                LS(j) = 117.3136
                CF(j) = 21737.57
                P(j) = 0.34
                Lim(j) = 9
                End If
                
                If Round(Asim, 2) > Round(117.3136, 2) Then
                j = 10
                LI(j) = 117.3136
                LS(j) = 4692544.4849
                CF(j) = 78404.57
                P(j) = 0.35
                Lim(j) = 10
                End If
                
                H = (CF(j) + (Asim - LI(j)) * P(j)) / (1 - P(j))
                If (H + Asim) > LS(j) Then H = (CF(j + 1) + (Asim - LI(j + 1)) * P(j) / (1 - P(j)))
                ISR(i) = H + Asim
                    If SRI > 2.95 Then
                        IMSS(i) = (SRI) * (24.501 + 2227.36301 * (PR + 0.0965) + 364.408)
                    Else
                        IMSS(i) = (2227.36301 * SRI * (PR + 0.0965) + 434.73216)
                    End If
                    
                actual = ISR(i) + IMSS(i)
                If actual < SMTM(i) Then SMTM(i) = actual
                
                SRI = SRI + 0.1
            Wend
                
        Next i
    Any help will be really grateful.

    Thanks!
    Last edited by raulge91; 07-21-2015 at 06:46 PM. Reason: Noob

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    Win10/MSO2016
    Posts
    13,000

    Re: If condition not met, but runs the statement.

    Your description is too vague (... get some values when a certain condition is met....). You must specify the condition(s).
    ....the statements are not met... (which statements?)
    ... but the procedure is being run... Do you mean the procedure you posted only a part of above?
    Last edited by protonLeah; 07-21-2015 at 08:16 PM.
    Ben Van Johnson

  3. #3
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: If condition not met, but runs the statement.

    Hi raulge,

    Maybe:

    If Round(1.9758, 2) < Round(Asim, 2) AND Round(Asim, 2) < Round(3.4722, 2) Then
    et al, et al
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA runs slow locally, runs fine when connected remotely
    By jbzy324 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-01-2015, 10:05 PM
  2. If statement result runs a MACRO
    By danmazz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-03-2013, 12:16 PM
  3. [SOLVED] Complicated IF statement that runs an equation on True
    By scrumpulate in forum Excel General
    Replies: 1
    Last Post: 04-20-2012, 04:24 PM
  4. condition:IF statement
    By MAHMUZ in forum Excel General
    Replies: 4
    Last Post: 10-08-2010, 02:46 PM
  5. If then statement to control when the script runs
    By realniceguy5000 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-29-2009, 06:42 PM
  6. Condition:If Statement
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-20-2006, 04:00 AM
  7. Condition Statement
    By Django in forum Excel General
    Replies: 5
    Last Post: 08-26-2005, 02:05 PM

Tags for this Thread

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