Posts Tagged ‘userforms’

Userforms:automatic calculations and transfer of data to Excel worksheet

Tuesday, July 28th, 2009

Userforms make data entry moe intuitive. The coding for transfer of data from the userform to the Excel worksheet is easy to learn. The code for the ‘AddData’ button is reproducd here for your ready reference. For more details you can log on to familycomputerclub.com.

Dim eRow As Long
Dim ws As Worksheet
Set ws = Worksheets(”data”)

‘find first empty row in database
eRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row

‘check for a name
If Trim(Me.txtName.Value) = “” Then
Me.txtPart.SetFocus
MsgBox “Please enter a name”
Exit Sub
End If

‘copy the data to the database
ws.Cells(eRow, 1).Value = Me.txtName.Value
ws.Cells(eRow, 2).Value = Me.txtSalary.Value
ws.Cells(eRow, 3).Value = Me.txtHRA.Value
ws.Cells(eRow, 4).Value = Me.txtPF.Value
ws.Cells(eRow,5).Value=Me.txtMed.Value
ws.Cells(eRow,6).Value=Me.txtPkg.Value

‘clear the data
Me.txtName.Value = “”
Me.txtSalary.Value = “”
Me.txtHRA.Value = “”
Me.txtPF.Value = “”
Me.txtMed.Value=”"
Me.txtPkg.Value = “”
Me.txtName.SetFocus

Duration : 0:3:21

(more…)