I would like to make the combination of UserForm and MessageBox but stuck with the code, can anyone help to rewrite the code correctly?
The idea is clicking CommandButton1 will prompt the message box, click Yes on the MessageBox the values on the Textboxes will be transferred into worksheet and textboxes will be cleared, click No will only close the MessageBox.
I got an error on the red highlighted area, and assume the code is properly written.
Code:
[U][COLOR=#ff0000]Private Sub CommandButton1_Click()[/COLOR][/U]
If MsgBox("Are you sure?", vbYesNo) = vbYes Then
Dim lRow As Long
Dim ws As Worksheet
Set ws = Worsheets("Sheet1")
lRow = ws.Cells(Rows.Count, 1).End(x1Up).Offset(1, 0).Row
With ws
.Cells(lRow, 1).Value = Me.TextBox1.Value
.Cells(lRow, 2).Value = Me.TextBox2.Value
End With
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
End If
End Sub
Private Sub Commandbutton2_click()
Unload Me
End Sub
The idea is clicking CommandButton1 will prompt the message box, click Yes on the MessageBox the values on the Textboxes will be transferred into worksheet and textboxes will be cleared, click No will only close the MessageBox.
I got an error on the red highlighted area, and assume the code is properly written.
Last edited: