summing and poulate values in multiple textboxes based on two columns in listbox on userform

Alaa mg

Active Member
Joined
May 29, 2021
Messages
343
Office Version
  1. 2019
hi
I search for how summing the values and show in textxboxes based on 2,3 columns in listbox . in column 2 is VCH contain cash and CHEQU in column 3 . so should summing the values are existed in last column in listbox and show in textboxes for VCH and the same thing for VCL contains CASH, CHEQU so should summing the values in column 4 in listbox..
short word the summing values depend on column 2,3 when summing the values as in picture.
LISTBOX.PNG
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
In your description and in the label you have "VCL" but in the sheet you have "VLC".

1634299221831.png



The macro reads "VCL".

Set the name of the listbox1, textbox1, textbox2, textbox3, and textbox4 controls.

VBA Code:
Private Sub CommandButton1_Click()
  Dim i As Long
  Dim vch_cash As Double, vcl_cash As Double
  Dim vch_cheq As Double, vcl_cheq As Double
  
  With ListBox1
    For i = 0 To .ListCount - 1
      If .List(i, 1) = "VCH" And .List(i, 2) = "CASH" Then vch_cash = vch_cash + CDbl(.List(i, 4))
      If .List(i, 1) = "VCH" And .List(i, 2) = "CHEQUE" Then vch_cheq = vch_cheq + CDbl(.List(i, 4))
      If .List(i, 1) = "VCL" And .List(i, 2) = "CASH" Then vcl_cash = vcl_cash + CDbl(.List(i, 3))
      If .List(i, 1) = "VCL" And .List(i, 2) = "CHEQUE" Then vcl_cheq = vcl_cheq + CDbl(.List(i, 3))
    Next
  End With
  TextBox1.Value = Format(vch_cash, "#,##0.00")
  TextBox2.Value = Format(vch_cheq, "#,##0.00")
  TextBox3.Value = Format(vcl_cash, "#,##0.00")
  TextBox4.Value = Format(vcl_cheq, "#,##0.00")
End Sub
 
Upvote 0
Solution
In your description and in the label you have "VCL" but in the sheet you have "VLC".
thanks for correcting me and I'm sorry I don't note it
now this is what I got . what's the problem?
LISTBOX.PNG
 

Attachments

  • LISTBOX.PNG
    LISTBOX.PNG
    13.2 KB · Views: 3
Upvote 0
1634311601181.png


You have serious problems with your data.
says "CAHS" should say "CASH".
Also check that there are no blank spaces after each word.

It would be easier if instead of an image, you put your data here with the XL2BB minisheet tool

Try with my data:
Dante Amor
ABCDE
1ITEMVOUCHERCASEDC
21VCHCASH10000
32VCLCHEQUE2000
43VCHCASH12000
54VCHCASH5000
65VCHCHEQUE2000
76VCHCHEQUE3000
87VCHCHEQUE1000
98VCLCHEQUE2500
109VCLCHEQUE500
1110VCLCHEQUE1000
1211VCLCHEQUE2000
1312VCLCASH2000
Hoja1


1634311814072.png
 
Upvote 0
sorry again . I lost my focus
excellent ! thanks very much ;)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

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