Sum of numbers in a list box

mmn1000

Board Regular
Joined
Mar 17, 2020
Messages
90
Office Version
  1. 2019
  2. 2013
Platform
  1. Windows
Hello
I have a list box inside a user form and I want to display the total amount in the list box in a text box or label
For this I used the following code
VBA Code:
Private Sub sum_subjects()
Dim total_v As Double
    For i = 0 To ListBox1.ListCount - 1
        total_v = total_v + Val(ListBox1.Column(5, i))
        geo_v = geo_v + Val(ListBox1.Column(6, i))
    Next
        sum_total.Caption = total_v
        sum_geo.Caption = geo_v
End Sub
The problem is that when I type in the search form, it displays the total. How do I modify the code to display the search total (limited filtered)?
 

Attachments

  • 3333.png
    3333.png
    15.1 KB · Views: 9
It looks like it is working for you. If you wanted to make a change so that when you press enter in the Title Textbox the form updated rather than each time the Title textbox changes do this:


Replace this
VBA Code:
Private Sub TextBox8_Change()

    If ComboBox1.Text <> Empty Then Call serchTel
    If TextBox8.Text = Empty Then Call addlist
    sum_subjects
End Sub

With this
VBA Code:
Private Sub TextBox8_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
  If KeyCode = 13 Then
    If ComboBox1.Text <> Empty Then Call serchTel
    If TextBox8.Text = Empty Then Call addlist
    sum_subjects
  End If
End Sub
Thank you for your help, my dear friend and brother Jeffrey Mahoney

Meysam Moghadamnia
 
Upvote 0

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