ExcelEndeavor
New Member
- Joined
- Oct 13, 2020
- Messages
- 49
- Office Version
- 365
- Platform
- MacOS
I have a listbox "lbxInvoiceList" that lists all invoices. The invoice amount is listed in column 3 of that listbox. I would like the total of column 3 to be shown in textbox "TxtInvoiceTotal". The code I have only works when one of the line items in the listbox is clicked. I would like to automatically display as soon as the userform "RequestForm" opens. Any ideas?
VBA Code:
Private Sub lbxInvoiceList_Change()
Call UpdateInvoiceTotal
End Sub
Code:
Private Sub UpdateInvoiceTotal()
Dim i As Integer
Dim total As Double
total = 0
' Loop through each item in the listbox
For i = 0 To lbxInvoiceList.ListCount - 1
' Sum the values in column 3 (index 2)
total = total + CDbl(lbxInvoiceList.List(i, 2))
Next i
' Populate the total in the textbox
TxtInvoiceTotal.Value = total
End Sub