PDA

View Full Version : [SOLVED:] Multiply two columns and sum a column in Listview



djemy1975
03-20-2016, 06:34 AM
Dear developpers,

I am stuck in a form to check calculations before sending them to worksheet .


I have to multiply two columns 3 and 5 and then sum column 6 total and display total in a listbox.

herewith my file for better clarifications and I am ready for any questions,

Thanks in advance,

Hafid
03-20-2016, 10:36 AM
Hello djemy,

you have to :

1. add another textbox named textTotal

2. add in your USF code these two procedures


Private Sub textPrix_Change()
textTotal.value = textPrix.value * textQté.value
End Sub

Private Sub textQté_Change()
textTotal.value = textPrix.value * textQté.value
End Sub

3. add in your Sub UserForm_Initialize :


Private Sub UserForm_Initialize()
Dim i As Long, Ttl As Currency
On Error Resume Next
For i = 1 To ListView1.ListItems.Count
Ttl = Ttl + CDbl(ListView1.ListItems(i).ListSubItems(5).Text)
Next
textHT.value = Ttl
End Sub

Cordially, Hafid

djemy1975
03-20-2016, 12:32 PM
Dear Hafid,

I am so leased to receive a quick rely .I will test your code and let you know if it is suitable.

Again thanks,

djemy1975
03-20-2016, 01:22 PM
Hi Hafid,

The first step is working (column 5 * column 3),but still the sum of column 6 is not working.Could you help me figure it out.

Thanks in advance,

Herewith my file amended

djemy1975
03-21-2016, 12:32 AM
Hello djemy,

you have to :

1. add another textbox named textTotal

2. add in your USF code these two procedures


Private Sub textPrix_Change()
textTotal.value = textPrix.value * textQté.value
End Sub

Private Sub textQté_Change()
textTotal.value = textPrix.value * textQté.value
End Sub

3. add in your Sub UserForm_Initialize :


Private Sub UserForm_Initialize()
Dim i As Long, Ttl As Currency
On Error Resume Next
For i = 1 To ListView1.ListItems.Count
Ttl = Ttl + CDbl(ListView1.ListItems(i).ListSubItems(5).Text)
Next
textHT.value = Ttl
End Sub

Cordially, Hafid

Again thank you I was able to figure it out depending on your code and it 's working like a charm now.

Many thanks Mr Hafid,