S
Stacy
I have completed a userform with the following fields:
FirstName LastName Phone Email Address City State Zip
I would like to have a command button that adds these to my worksheet.
I would also like to add check boxes so they can select any initerests they
may have like transportaion, schools, safety. These can show up as an x in
the cell if selected and blank if not.
I have read and reread posts, help, goolgled them all and am still having
trouble learning how to do this. Can anybody help me with the code, or
point me to example add command codes?
I have pasted the only thing I can find with my changes below, but it does
not work and I don't know what I am doing it is just a mess.
Thanks!
Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("PersonalInfoUpdate") ****getting runtime error "9"
subscript out of range error here.
'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
'copy the data to the database
ws.Cells(iRow, 1).Value = Me.txtFirstName.Value
ws.Cells(iRow, 2).Value = Me.txtLastName.Value
ws.Cells(iRow, 3).Value = Me.txtPhone.Value
ws.Cells(iRow, 4).Value = Me.txtEmail.Value
ws.Cells(iRow, 5).Value = Me.txtAddress.Value
ws.Cells(iRow, 6).Value = Me.txtCity.Value
ws.Cells(iRow, 7).Value = Me.txtState.Value
ws.Cells(iRow, 8).Value = Me.txtZip.Value
'clear the data
Me.txtFirstName.Value = ""
Me.txtLastName.Value = ""
Me.txtPhone.Value = ""
Me.txtEmail.Value = ""
Me.txtAddress.SetFocus
Me.txtCity.Value = ""
Me.txtState.Value = ""
Me.txtZip.Value = ""
End Sub
FirstName LastName Phone Email Address City State Zip
I would like to have a command button that adds these to my worksheet.
I would also like to add check boxes so they can select any initerests they
may have like transportaion, schools, safety. These can show up as an x in
the cell if selected and blank if not.
I have read and reread posts, help, goolgled them all and am still having
trouble learning how to do this. Can anybody help me with the code, or
point me to example add command codes?
I have pasted the only thing I can find with my changes below, but it does
not work and I don't know what I am doing it is just a mess.
Thanks!
Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("PersonalInfoUpdate") ****getting runtime error "9"
subscript out of range error here.
'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
'copy the data to the database
ws.Cells(iRow, 1).Value = Me.txtFirstName.Value
ws.Cells(iRow, 2).Value = Me.txtLastName.Value
ws.Cells(iRow, 3).Value = Me.txtPhone.Value
ws.Cells(iRow, 4).Value = Me.txtEmail.Value
ws.Cells(iRow, 5).Value = Me.txtAddress.Value
ws.Cells(iRow, 6).Value = Me.txtCity.Value
ws.Cells(iRow, 7).Value = Me.txtState.Value
ws.Cells(iRow, 8).Value = Me.txtZip.Value
'clear the data
Me.txtFirstName.Value = ""
Me.txtLastName.Value = ""
Me.txtPhone.Value = ""
Me.txtEmail.Value = ""
Me.txtAddress.SetFocus
Me.txtCity.Value = ""
Me.txtState.Value = ""
Me.txtZip.Value = ""
End Sub