Excel VBA UserForm Programming Part 2

Published: 12 March 2016
on channel: Tutorial Spot
272
4

In Part 2 we look at putting the code behind our UserForm to give it some use.

Code for the Submit button:

Private Sub submitBTN_Click()
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
Dim choice As Integer
Dim newRow As Long
newRow = Application.WorksheetFunction.CountA(ws.Range("B:B")) + 2

If depositOPT = False And withdrawOPT = False Then
MsgBox "Select an option: Deposit or Withdraw"
Exit Sub
End If

If depositOPT = True Then
choice = 3
ws.Cells(newRow, 2).Value = Me.bookieTXT.Value
ws.Cells(newRow, choice).Value = Me.amountTXT.Value
Me.amountTXT.Value = ""
Me.bookieTXT.Value = ""
End If

If withdrawOPT = True Then
choice = 4
ws.Cells(newRow, 2).Value = Me.bookieTXT.Value
ws.Cells(newRow, choice).Value = Me.amountTXT.Value
Me.amountTXT.Value = ""
Me.bookieTXT.Value = ""
End If

End Sub

If you're reading this far, I've added some more lines of code to clear the text boxes and the option buttons.


Watch video Excel VBA UserForm Programming Part 2 online, duration hours minute second in high quality that is uploaded to the channel Tutorial Spot 12 March 2016. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 272 times and liked it 4 visitors.