how show total value in textbox on userform when run the form ?

Hasson

Active Member
Joined
Apr 8, 2021
Messages
390
Office Version
  1. 2016
Platform
  1. Windows
hello
I need help to show the TOTAL value in textbox2 when run userform . so after search the item in textbox1 and show the data in listbox .it should summing the values in col 5 in listbox and show the result in textbox2
this is my code
VBA Code:
Private Sub TextBox1_Change()
If TextBox1.Value = "" Then ListBox1.Clear: Exit Sub
Dim x As Worksheet

         ListBox1.Clear
    k = 0
For Each x In ThisWorkbook.Worksheets
        ss = x.Cells(Rows.Count, 1).End(xlUp).Row
        For Each C In x.Range("B2:B" & ss)
            b = InStr(C, TextBox1)
            If b > 0 Then
                ListBox1.AddItem
                ListBox1.List(k, 0) = x.Cells(C.Row, 1).Value
                ListBox1.List(k, 1) = x.Cells(C.Row, 2).Value
                ListBox1.List(k, 2) = x.Cells(C.Row, 3).Value
                ListBox1.List(k, 3) = x.Cells(C.Row, 4).Value
                ListBox1.List(k, 4) = x.Cells(C.Row, 5).Value
                ListBox1.List(k, 5) = x.Cells(C.Row, 6).Value
                
                k = k + 1
            End If
        Next C

Next x
End Sub
thanks
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Try this

Rich (BB code):
Private Sub TextBox1_Change()
If TextBox1.Value = "" Then ListBox1.Clear: Exit Sub
Dim x As Worksheet

         ListBox1.Clear
    k = 0
    textbox2.Value = 0
For Each x In ThisWorkbook.Worksheets
        ss = x.Cells(Rows.Count, 1).End(xlUp).Row
        For Each C In x.Range("B2:B" & ss)
            b = InStr(C, TextBox1)
            If b > 0 Then
                ListBox1.AddItem
                ListBox1.List(k, 0) = x.Cells(C.Row, 1).Value
                ListBox1.List(k, 1) = x.Cells(C.Row, 2).Value
                ListBox1.List(k, 2) = x.Cells(C.Row, 3).Value
                ListBox1.List(k, 3) = x.Cells(C.Row, 4).Value
                ListBox1.List(k, 4) = x.Cells(C.Row, 5).Value
                ListBox1.List(k, 5) = x.Cells(C.Row, 6).Value
                textbox2.Value = textbox2.Value + x.Cells(C.Row, 6).Value
                k = k + 1
            End If
        Next C

Next x
End Sub
 
Upvote 0
Where do you have the values in E or in F?
If it is E, then:

textbox2.Value = textbox2.Value + x.Cells(C.Row, 5).Value

Or you could put a sample of one of your sheets.
 
Upvote 0
Solution
Im glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,857
Members
449,051
Latest member
excelquestion515

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