Userform combobox, allow user to add data

reynold

New Member
Joined
Nov 7, 2015
Messages
13
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.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Your code that errors works for me. Does this work for you?

Rich (BB code):
Private Sub CommandButton1_Click()
    Dim ws As Worksheet
    Dim lastrow As Long
    Set ws = ThisWorkbook.Sheets("List")
    Sheets("List").Unprotect Password:="SBPL"
    ws.ListObjects("listofservices").ListRows.Add
    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
 
Upvote 0

Forum statistics

Threads
1,223,155
Messages
6,170,405
Members
452,325
Latest member
BlahQz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top