maninjapan
09-10-2008, 11:14 PM
I am trying to make a userform that requires multiple data entries.
Clicking the Ok button enters all the data into spreadsheet.
However if even one piece of Data is missing I want it to bring up a warning stating what needs to be entered. I have tried this for one piece of data and the MsgBox works fine, however it still enters the rest of the data. Im trying to get it to only transfer the data to the spreadsheet once all the data is entered correctly.
So far this is what I have......
Private Sub CommandNextContract_Click()
' 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"
ComboBoxContract.SetFocus
' Ensures Trader is selected
If ComboBoxTrader.Text = "" Then
MsgBox "Please select Trader"
ComboBoxTrader.SetFocus
Exit Sub
End If
End Sub
Clicking the Ok button enters all the data into spreadsheet.
However if even one piece of Data is missing I want it to bring up a warning stating what needs to be entered. I have tried this for one piece of data and the MsgBox works fine, however it still enters the rest of the data. Im trying to get it to only transfer the data to the spreadsheet once all the data is entered correctly.
So far this is what I have......
Private Sub CommandNextContract_Click()
' 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"
ComboBoxContract.SetFocus
' Ensures Trader is selected
If ComboBoxTrader.Text = "" Then
MsgBox "Please select Trader"
ComboBoxTrader.SetFocus
Exit Sub
End If
End Sub