counting

johnster

New Member
Joined
May 31, 2018
Messages
43
Can anyone help me with this?

I have a Textbox and a List box with a delete button so i can remove the last row. In my listbox there are 2 columns (1st names and 2nd prices). My textbox counts the second row (prices).
The delete button is doing it but does not counts down in my textbox. Can Someone complete the code please?

Here is my code so far without counting down.

Private Sub CommandButton84_Click()
Dim ItemTarget As Long
ItemTarget = ListBox1.ListCount
If ItemTarget > 0 Then
ListBox1.RemoveItem ItemTarget - 1
End If
End Sub




 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Where are the controls, worksheet or user form?

Code:
Private Sub CommandButton1_Click()
Dim ItemTarget&
ItemTarget = ListBox1.ListCount
If ItemTarget > 0 Then
    Me.ListBox1.RemoveItem ItemTarget - 1
    Me.TextBox1 = Me.ListBox1.ListCount
End If
End Sub


Private Sub UserForm_Initialize()
With Me.ListBox1
    .ColumnCount = 2
    .Locked = False
    .ColumnHeads = True
    .RowSource = ""
    .List = Sheets("sheet2").[j11:k17].Value
End With
End Sub
 
Upvote 0
Capture.png
[/URL][/IMG]
The buttons and textbox are in the userform

when i click the "DEL" button in the Userform my textbox show me the total items there are in my Listbox.
jEhTf8
 
Last edited:
Upvote 0
I understood that you wanted the number of rows in the list box. If it is not this, please explain.
What did you mean by counting the prices?
 
Upvote 0
Like this:

Code:
Private Sub CommandButton1_Click()
Dim ItemTarget&, s, i%
s = 0
ItemTarget = ListBox1.ListCount
If ItemTarget > 0 Then
    Me.ListBox1.RemoveItem ItemTarget - 1
    For i = 0 To Me.ListBox1.ListCount - 1
        s = s + Val(Me.ListBox1.List(i, 1))
    Next
    Me.TextBox1 = s
End If
End Sub
 
Upvote 0
Worf, Thank you so much.
I have just still one issue. It counts wrong on my PC but on another it's correct. This is the code for each commandbutton



Private Sub CommandButton1_Click()
With ThisWorkbook.Sheets("Sheet1")
Me.ListBox1.AddItem .Range("B2").Value
Me.ListBox1.Column(1, ListBox1.ListCount - 1) = .Range("C2").Value
Me.TextBox1.Value = CDbl(Me.TextBox1.Value) + .Range("C2").Value
End With
End Sub

1.6 + 1.6 = 17.6 very expensive coca cola :-)

2ciag6f.jpg
[/IMG]
 
Last edited:
Upvote 0
Ok so far so good. Everything is working well now but i have another question.

I want to keep an inventary with all the products that are sold for today. Maybe it's possible to
create a seperated workbook that will automatically create date sheets and store the date of that day?


Maybe it's easier to download my project so you can see what i mean
https://johnneke886.stackstorage.com/s/44GyI1dNBPngech
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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