Consulting

Results 1 to 5 of 5

Thread: Nested If

  1. #1
    VBAX Tutor
    Joined
    Sep 2008
    Posts
    213
    Location

    Nested If

    Im having a bit of trouble getting this to work, I believe the problem is with the first line....

    [VBA]
    If ComboBoxAccount.Text = "A1946" Or "A3448" Or "A3453" Then
    If ComboBoxContract.Text = "FDAX" Then
    Cells(NextRow, 6) = TextBoxPL.Text
    Cells(NextRow, 7) = TextBoxPL.Text * Cells(NextRow, 5)
    Cells(NextRow, 9) = (TextBoxLots.Text * TextBoxExchangeRate.Text) + (TextBoxLots.Text * 0.8)
    ElseIf ComboBoxContract.Text = "FESX" Then
    Cells(NextRow, 6) = TextBoxPL.Text
    Cells(NextRow, 7) = TextBoxPL.Text * Cells(NextRow, 5)
    Cells(NextRow, 9) = (TextBoxLots.Text * TextBoxExchangeRate.Text * 0.6) + (TextBoxLots.Text * 0.8)
    ElseIf ComboBoxContract.Text = "Z" Then
    Cells(NextRow, 6) = TextBoxPL.Text
    Cells(NextRow, 7) = TextBoxPL.Text * Cells(NextRow, 5)
    Cells(NextRow, 9) = (TextBoxLots.Text * TextBoxExchangeRate.Text * 0.56) + (TextBoxLots.Text * 0.8)
    Else: Cells(NextRow, 7) = TextBoxPL.Text
    Cells(NextRow, 9) = TextBoxLots.Text * (strCommission + 0.3)
    End If
    Else if......
    End If
    End If


    [/VBA]

  2. #2
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,198
    Location
    is "A1946" refering to a cell on a worksheet, if it is would it not be Sheet("Whatever").Range("A1946").Value or am i missing something.
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  3. #3
    VBAX Tutor
    Joined
    Sep 2008
    Posts
    213
    Location
    sorry, I can see how that would look like a cell. Actually its an account number. Im Trying to total and display Net P/Ls

  4. #4
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Each OR must seperate a test, like:

    [vba]Sub Fake()
    Dim i As Integer
    i = 3

    If i = 12 _
    Or i = 13 _
    Or i = 10 Then
    MsgBox "Hi!", 0, ""
    ElseIf i = 3 _
    Or i = 4 _
    Or i = 1 Then
    MsgBox "Ho", 0, ""
    Else
    MsgBox "The gang is all here.", 0, ""
    End If

    End Sub[/vba]

    Also - kill the last 'End If'

    Mark

  5. #5
    VBAX Tutor
    Joined
    Sep 2008
    Posts
    213
    Location
    GTO, Right, that makes sense. Thanks a lot.

Posting Permissions

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