Consulting

Results 1 to 3 of 3

Thread: Else error

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

    Else error

    Im trying the following code, but getting an error on the Else.....

    Says there is no If for it......

    Private Sub CommandNextContract_Click()
    ' Ensure all data is entered

    If ComboBoxTrader.Text = "" Or _
    ComboBoxContract.Text = "" Or _
    ComboBoxmonth.Text = "" Or _
    TextBoxLots.Text = "" Or _
    TextBoxPL.Text = "" Or _
    ComboBoxCurrency.Text = "" Or _
    TextBoxExchangeRate.Text = "" Then _
    MsgBox "Enter Data!", vbInformation, "Error Message"
    TextBoxDate.SetFocus
    Exit Sub

    Else





    ' Make sure Sheet1 is active
    Sheets("Sheet1").Activate

    ' Determine the next empty row
    NextRow = _
    Application.WorksheetFunction.CountA(Range("A:A")) + 1

    ' Transfer the Date,Trader,Contract,Month,Lots,P&L,Currency
    Cells(NextRow, 1) = TextBoxDate.Text
    Cells(NextRow, 2) = ComboBoxTrader.Text
    Cells(NextRow, 3) = ComboBoxContract.Text
    Cells(NextRow, 4) = ComboBoxmonth.Text
    Cells(NextRow, 5) = TextBoxLots.Text
    Cells(NextRow, 6) = TextBoxPL.Text
    Cells(NextRow, 7) = ComboBoxCurrency.Text

    ' Clear Trade Info for next entry
    ComboBoxContract.Text = ""
    ComboBoxmonth.Text = ""
    TextBoxLots.Text = ""
    TextBoxPL.Text = ""
    ComboBoxCurrency.Text = "USD"
    TextBoxExchangeRate.Text = "1"

    ComboBoxContract.SetFocus
    End If



    End Sub

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    At the end of your IF conditions, you include a line continuation character. Get rid of that first, and see if it's fixed.

    [VBA] TextBoxExchangeRate.Text = "" Then _
    MsgBox "Enter Data!", vbInformation, "Error Message"
    TextBoxDate.SetFocus
    [/VBA]

  3. #3
    VBAX Tutor
    Joined
    Sep 2008
    Posts
    213
    Location
    Great Stuff GTO, works like a charm. Thanks for your help

Posting Permissions

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