abdelfattah
Well-known Member
- Joined
- May 3, 2019
- Messages
- 1,507
- Office Version
- 2019
- 2010
- Platform
- Windows
hi, everyone
i have sheet contains data begins a3:h10000 i try writing code about function sumif to show me the total values into textbox2 , textbox3 it gives me total=0 of course it also contains the userform combobox 1 when i choose additem in combobox1 it suppose gives me the total in textbox2,3 the total in textbox2 it depends on 2 columns d= values and h= name textbox3 it deoends on 2 columns e= values h= name
this is my code
i have sheet contains data begins a3:h10000 i try writing code about function sumif to show me the total values into textbox2 , textbox3 it gives me total=0 of course it also contains the userform combobox 1 when i choose additem in combobox1 it suppose gives me the total in textbox2,3 the total in textbox2 it depends on 2 columns d= values and h= name textbox3 it deoends on 2 columns e= values h= name
this is my code
VBA Code:
Private Sub ComboBox1_Change()
Dim ws As Worksheet
Dim Rng As Range
Dim Sel
Set ws = Sheets("sheet2")
Sel = Me.ComboBox1.Value
If Sel <> "" Then
Set Rng = ws.Columns(2).Find(Sel, lookat:=xlWhole)
If Not Rng Is Nothing Then
Me.TextBox1.Value = ws.Cells(Rng.Row, "c")
Me.TextBox2.Value = Application.WorksheetFunction.SumIf(Range("d:d"), Me.ComboBox1, Range("g:g"))
Me.TextBox3.Value = Application.WorksheetFunction.SumIf(Range("e:e"), Me.ComboBox1, Range("g:g"))
Me.TextBox4 = Val(Me.TextBox2.Value) - Val(Me.TextBox3.Value)
End If
End Sub