abdo meghari
Well-known Member
- Joined
- Aug 3, 2021
- Messages
- 712
- Office Version
- 2019
Hello ,
in TB2 will search for BRAND after select optionbutton1,optionutton2 based on sheet name .
so what I want to sum column 5 and put in TB3 , TB4 = sum column 7 and divide on sum column 5 (80,150.00/40.00=2,003.75), TB5= TB3*TB4
and populate column 3 and put in TB1
this is what I have
this is what I want
this code is search BRAND when write in TB2
I hope anybody can help.
in TB2 will search for BRAND after select optionbutton1,optionutton2 based on sheet name .
so what I want to sum column 5 and put in TB3 , TB4 = sum column 7 and divide on sum column 5 (80,150.00/40.00=2,003.75), TB5= TB3*TB4
and populate column 3 and put in TB1
this is what I have
this is what I want
this code is search BRAND when write in TB2
VBA Code:
Option Explicit
Dim a As Variant
Sub FilterData()
Dim txt1 As String
Dim i As Long, j As Long, k As Long
ListBox1.Clear
ReDim b(1 To UBound(a, 1), 1 To UBound(a, 2))
For i = 1 To UBound(a)
If TextBox2 = "" Then txt1 = a(i, 4) Else txt1 = TextBox2
If LCase(a(i, 4)) Like LCase(txt1) & "*" Then
k = k + 1
For j = 1 To 7
If j = 1 Then 'Change the 1 in this line for the column number where you have the date
b(k, j) = Format(a(i, j), "dd/mm/yyyy")
Else
b(k, j) = a(i, j)
End If
Next
End If
Next
If k > 0 Then ListBox1.List = b
With ListBox1
.ColumnWidths = "80;80;80;180;100;80;80"
For i = 0 To .ListCount - 1
.List(i, 4) = Format(.List(i, 4), "#,##0.00")
.List(i, 5) = Format(.List(i, 5), "#,##0.00")
.List(i, 6) = Format(.List(i, 6), "#,##0.00")
Next i
End With
End Sub
Private Sub OptionButton1_Click()
If OptionButton1.Value = True And OptionButton2.Value = False Then sheet5.Select
Call ChangeSheet
Call FilterData
End Sub
Private Sub OptionButton2_Click()
If OptionButton2.Value = True And OptionButton1.Value = False Then sheet6.Select
Call ChangeSheet
Call FilterData
End Sub
Private Sub TextBox2_Change()
Call FilterData
End Sub
Private Sub ChangeSheet()
With ActiveSheet
a = .Range("A2:G" & .Range("D" & Rows.Count).End(3).Row).Value
End With
End Sub