Userform Listbox - Button to add +1 or -1 in same row as selected

Mathericnl

New Member
Joined
Feb 16, 2022
Messages
15
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I can't seem to find the solution for the following:

When I select a certain row. I want a button to add +1 to the cell inside this selection in front of the productname.
But, if value is 1. It should not be visible. Only if value is >2.

Names:
Listbox1
Sheet:
Worksheet(''ActieveB'') cells in Column B.

If I select Margaritha and press the + button. I want Cell B2 to say 2. If I press the - button, it should go back to 1.

listbox.png


excel.png




Should look like:
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
You can put here the line of code or instruction with which you load the data to the listbox.

In addition to updating the cell, do you also want the change to be seen in the listbox?
 
Upvote 0
You can put here the line of code or instruction with which you load the data to the listbox.

In addition to updating the cell, do you also want the change to be seen in the listbox?

The listbox already reads the sheet to show data in listbox.
From the userform I would like to be able to add +1 to the product if a order has 2.

For Example I put in the lovely pizza's:

Order:
2 Margaritha's
5 Salami's

What does it now?:
I can add Margaritha and Salami by pressing the left buttons.
This will add the name in column C of the spreadsheet.
The listbox shows all data in spreadsheet again.

Order:
2 Margaritha's
5 Salami's
-------------------------------------------------------
I want to show the order above as:
2x Margaritha
5x Salami
-------------------------------------------------------
Now I have to put it seperately:
Margaritha
Margaritha
Salami
Salami
Salami
Salami
Salami

excel.png
 
Upvote 0
Also for the ''Delete'' Button I have this code:

VBA Code:
Private Sub CommandButton76_Click()
Dim i As Integer

For i = 1 To Range("B10000").End(xlUp).Row
    If Cells(i, 1) = ListBox1.List(ListBox1.ListIndex) Then
    Rows(i).Select
    Selection.Delete
    End If
Next i

End Sub

It doesn't work properly. When I use the delete button. It just deletes randomly data in the sheet.
 
Upvote 0
I already understood this:
" I would like to be able to add +1 to the product if a order has 2."


What I want to know, and you didn't answer, is how did you add "Margarita" to the listbox.
What instruction or method or code do you use to put the item in the listbox.
You use Rowsource, List, Additem.
I want you to put here the instruction you are using to fill the listbox.
 
Upvote 0
oh sorry for my misunderstanding.

VBA Code:
Private Sub CommandButton79_Click()

'Margaritha

    Sheets("ActieveB").Select
    Range("C1048575").Select
    Selection.End(xlUp).Select
    ActiveCell.Offset(1, 0).Range("A1").Select
    ActiveCell.FormulaR1C1 = "Margaritha"
End Sub
 
Upvote 0
I named Columns B:C:D as a name and put it in the rowsource of the listbox.
 
Upvote 0
Again, you can put the exact statement you use to load the data in the listbox.
And what exactly is the range you have in the named range
 
Upvote 0
I didn't use a code to load the data

I named Column B:C:D as Honderdeen and put in the Rowsource below.
.
listbox.png
 
Upvote 0

Forum statistics

Threads
1,214,858
Messages
6,121,960
Members
449,057
Latest member
FreeCricketId

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