Hello Experts
I am developing a userform, most of things are done, Only point where i am stuck is:
Allowing users to add data in combobox list.
Combo box property rowsource is referred to a table "listofservices"
There are basically two userforms:
Userform 1: which has Combo box (rowsource referred to a table "listofservices")(Userform 1 has a button to add services when clicked opens userform 2)
Userform 2: Displays textbox to enter data. When clicked Save, it should add data to Lastrow+1 of the table "listofservices"
But, the problem area is, it overwrights the lastrow.
Private Sub CommandButton1_Click()
Dim ws As Worksheet
Dim lastrow As Long
Set ws = ThisWorkbook.Sheets("List")
Sheets("List").Unprotect Password:="SBPL"
lastrow = ws.Range("listofservices").Rows.Count
ws.Cells(lastrow + 1, 1) = UserForm2.tbaddservice
ws.Cells(lastrow + 1, 9) = Val(UserForm2.tbaddogprice)
Me.Hide
End Sub
If i use
lastrow = ws.ListObjects("listofservices").Range.Rows.Count,
then it give a Run-Time error "Method '_Default" of object "range"failed,
If i click debug error and restarts my excel file.
Please help,
If there is any other way to allow users to add record in userform combolist, please suggest..
Thanks,
Reynold.
I am developing a userform, most of things are done, Only point where i am stuck is:
Allowing users to add data in combobox list.
Combo box property rowsource is referred to a table "listofservices"
There are basically two userforms:
Userform 1: which has Combo box (rowsource referred to a table "listofservices")(Userform 1 has a button to add services when clicked opens userform 2)
Userform 2: Displays textbox to enter data. When clicked Save, it should add data to Lastrow+1 of the table "listofservices"
But, the problem area is, it overwrights the lastrow.
Private Sub CommandButton1_Click()
Dim ws As Worksheet
Dim lastrow As Long
Set ws = ThisWorkbook.Sheets("List")
Sheets("List").Unprotect Password:="SBPL"
lastrow = ws.Range("listofservices").Rows.Count
ws.Cells(lastrow + 1, 1) = UserForm2.tbaddservice
ws.Cells(lastrow + 1, 9) = Val(UserForm2.tbaddogprice)
Me.Hide
End Sub
If i use
lastrow = ws.ListObjects("listofservices").Range.Rows.Count,
then it give a Run-Time error "Method '_Default" of object "range"failed,
If i click debug error and restarts my excel file.
Please help,
If there is any other way to allow users to add record in userform combolist, please suggest..
Thanks,
Reynold.