Consulting

Results 1 to 2 of 2

Thread: Skipping Over If Statement

  1. #1

    Post Skipping Over If Statement

    Below is my code showing if SumXj equals 1 then do the listed tasks. When I step into each line, the output shows SumXj reaches 1 around the 9th iteration. Instead of doing the listed tasks under SumXj =1, it skips over the tasks and into the following ElseIf, looping again. Can someone explain why this is happening? Thank you

    If Sum1 > 1 And Sum2 > 1 Then       'Two-Phase Region
        SumXj = 0
        For g = 0.01 To 1 Step 0.01
            For i = 1 To n
                LiqX = (Z(i) / (1 + Sng(g) * (K(i) - 1)))
                SumXj = SumXj + LiqX
                Cells(i + 7, 13).Value = SumXj
            If SumXj = 1 Then
                Sng = Sng(i)
                SnL = 1 - Sng(i)
            ElseIf SumXj < 1 Then
                End If
            Next i
        Next g
    Last edited by SamT; 11-07-2014 at 08:42 PM.

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Are you absolutely positive that LiqX is an Integer or a long?

    Depending on the values required use

    If SumXj >= 1 Then
         '
         'More code here
         '
    'ElseIF SumXj < 1
         '
         'Assuming you left out code here
         '
    End If
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

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