johnster

New Member
Joined
May 31, 2018
Messages
41
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




 

Some videos you may like

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Worf

Well-known Member
Joined
Oct 30, 2011
Messages
4,010
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
 

johnster

New Member
Joined
May 31, 2018
Messages
41
[URL="https://ibb.co/jEhTf8"][IMG]https://image.ibb.co/nKtZL8/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.
 
Last edited:

Worf

Well-known Member
Joined
Oct 30, 2011
Messages
4,010

ADVERTISEMENT

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?
 

Worf

Well-known Member
Joined
Oct 30, 2011
Messages
4,010

ADVERTISEMENT

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
 

johnster

New Member
Joined
May 31, 2018
Messages
41
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 :)

[IMG]http://i63.tinypic.com/2ciag6f.jpg[/IMG]
 
Last edited:

johnster

New Member
Joined
May 31, 2018
Messages
41
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
 

Watch MrExcel Video

Forum statistics

Threads
1,109,337
Messages
5,528,108
Members
409,802
Latest member
joeino

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top