Saturday, November 26, 2022

Create Userform In Excel With & Without VBA


VBA Code for Submit Button:

Private Sub CommandButton1_Click()

Dim Lastrow As Integer

Lastrow = Sheets("VBA").UsedRange.SpecialCells(xlCellTypeLastCell).Row + 1

'Transfee data to VBA Sheet

Sheets("VBA").Cells(Lastrow, 1) = TextBox1.Text
Sheets("VBA").Cells(Lastrow, 2) = TextBox2.Text
Sheets("VBA").Cells(Lastrow, 3) = TextBox3.Text
Sheets("VBA").Cells(Lastrow, 4) = TextBox4.Text
Sheets("VBA").Cells(Lastrow, 5) = Now

'clear Data

Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.TextBox4.Value = ""

End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)

If CloseMode = vbFormControlMenu Then

Cancel = True
MsgBox "Please use the close button to close the form", vbOKOnly

End If

End Sub


VBA Code for Cancel Button:

Private Sub CommandButton2_Click()

Unload UserForm1

End Sub

How To Use Vlookup In Merged Cells

  How To Use Vlookup In Merged Cells Click Here to download sample file for practice Note: Download the file and open with microsoft excel