863,783 views 198 on YTPak
1,139 139

Published on 15 Apr 2012 | over 5 years ago

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

Loading related videos...
(function(){ var spoutjs=document.createElement('script'),firstjs=document.getElementsByTagName('script')[0]; spoutjs.async=1; spoutjs.src='//cdn.spoutable.com/0f93c30c-199b-4e71-90dc-dbb5de72cee5/spoutable.js'; firstjs.parentNode.insertBefore(spoutjs,firstjs) })(); */ ?>