How to: Create a simple Userform in Excel

Please login in order to report media.

  • Uploaded 9 months ago in the category How to programming

    My first tutorial showing how to create a simple user form using excel.

    Thanks for watching.

    The code needed for the "add details" button:

    Dim iRow As Long
    Dim ws As Worksheet
    Set ws = Worksheets("Sheet1")

    'find first empty row in database
    iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
    SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1

    'check for a Name number
    If Trim(Me.textbox_name.Value) = "" Then
    Me.textbox_Name.SetFocus
    MsgBox "Please complete the form"
    Exit Sub
    End If

    'copy the data to the database
    ws.Cells(iRow, 1).Value = Me.textbox_name.Value
    ws.Cells(iRow, 2).Value = Me.textbox_surname.Value
    ws.Cells(iRow, 3).Value = Me.textbox_age.Value
    ws.Cells(iRow, 4).Value = Me.textbox_gender.Value

    MsgBox "Data added", vbOKOnly + vbInformation, "Data Added"
    'clear the data
    Me.textbox_name.Value = ""
    Me.textbox_surname.Value = ""
    Me.textbox_age.Value = ""
    Me.textbox_gender.Value = ""
    Me.textbox_name.SetFocus

  • how:createsimpleuserformexcel