hello,
I try adding the currency to textboxe2,3 and listbox after populate data based on textbox1 by select one of option button
based on picture after populate values .
when select one of the optionbuttons , for instance LYD then should add the currency before the numbers into textbox2,3 and the column 7,9 in listbox like this
this is the whole code .
and I try adding some codes but doesn't work
any suggestion to help?
I try adding the currency to textboxe2,3 and listbox after populate data based on textbox1 by select one of option button
based on picture after populate values .
when select one of the optionbuttons , for instance LYD then should add the currency before the numbers into textbox2,3 and the column 7,9 in listbox like this
this is the whole code .
VBA Code:
Option Explicit
Dim a As Variant
Private Sub TextBox1_Change()
Call FilterData
End Sub
Private Sub TextBox2_Change()
Call FilterData
End Sub
Private Sub TextBox3_Change()
Call FilterData
End Sub
Sub FilterData()
Dim i As Long, ii As Long, n As Long
Me.ListBox1.List = a
If Me.TextBox1 = "" Then Exit Sub
With Me.ListBox1
.Clear
For i = 0 To UBound(a, 1)
If UCase$(a(i, 3)) Like UCase$(Me.TextBox1) & "*" Then
.AddItem
.List(n, 0) = n + 1
For ii = 1 To UBound(a, 2)
.List(n, ii) = a(i, ii)
Next
n = n + 1
End If
Next
End With
Dim r As Long
Dim MySum, MySum1 As Double
MySum = 0
MySum1 = 0
With ListBox1
For r = 0 To .ListCount - 1
MySum = MySum + .List(r, 7)
MySum1 = MySum1 + .List(r, 9)
Next r
End With
TextBox2.Value = Format(MySum, "#,##0.00")
TextBox3.Value = Format(MySum1, "#,##0.00")
End Sub
Private Sub UserForm_Activate()
End Sub
Private Sub UserForm_Initialize()
Dim lindex&
Dim rngDB As Range, rng As Range
Dim i, myFormat(1) As String
Dim sWidth As String
Dim vR() As Variant
Dim n As Integer
Dim myMax As Single
Set rngDB = Range("A2:J20")
For Each rng In rngDB
n = n + 1
ReDim Preserve vR(1 To n)
vR(n) = rng.EntireColumn.Width
Next rng
myMax = WorksheetFunction.Max(vR)
For i = 1 To n
vR(i) = myMax
Next i
With Sheets("purchase").Cells(1).CurrentRegion
myFormat(0) = .Cells(2, 8).NumberFormatLocal
myFormat(1) = .Cells(2, 9).NumberFormatLocal
Set rng = .Offset(1).Resize(.Rows.Count - 1)
a = .Cells(1).CurrentRegion.Value
End With
sWidth = Join(vR, ";")
Debug.Print sWidth
With ListBox1
.ColumnCount = 10
.ColumnWidths = sWidth '<~~ 63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63
.List = rng.Value
.BorderStyle = fmBorderStyleSingle
For lindex = 0 To .ListCount - 1
'.List(lindex, 0) = (Format((.List(lindex, 0)), "dd/mm/yyyy")) ' BL = dates
.List(lindex, 0) = lindex + 1
.List(lindex, 7) = Format$(.List(lindex, 7), myFormat(0))
.List(lindex, 8) = Format$(.List(lindex, 8), myFormat(1))
.List(lindex, 9) = Format$(.List(lindex, 9), myFormat(1))
Next
a = .List
'<--- this line
End With
End Sub
VBA Code:
Private Sub OptionButton1_Click()
If OptionButton1.Value = True Then
If IsNumeric(TextBox2.Value) And IsNumeric(TextBox3.Value) Then
TextBox2.Value = OptionButton1.Value
TextBox3.Value = OptionButton1.Value
ListBox1.List(lindex, 7) = Format$(ListBox1.List(lindex, 7), myFormat(0)) = OptionButton1.Value
ListBox1.List(lindex, 9) = Format$(ListBox1.List(lindex, 9), myFormat(1)) = OptionButton1.Value
End If
End If
End Sub
Private Sub OptionButton2_Click()
If OptionButton2.Value = True Then
If IsNumeric(TextBox2.Value) And IsNumeric(TextBox3.Value) Then
TextBox2.Value = OptionButton2.Value
TextBox3.Value = OptionButton2.Value
ListBox1.List(lindex, 7) = Format$(ListBox1.List(lindex, 7), myFormat(0)) = OptionButton2.Value
ListBox1.List(lindex, 9) = Format$(ListBox1.List(lindex, 9), myFormat(1)) = OptionButton2.Value
End If
End If
End Sub
Private Sub OptionButton3_Click()
If OptionButton3.Value = True Then
If IsNumeric(TextBox2.Value) And IsNumeric(TextBox3.Value) Then
TextBox2.Value = OptionButton3.Value
TextBox3.Value = OptionButton3.Value
ListBox1.List(lindex, 7) = Format$(ListBox1.List(lindex, 7), myFormat(0)) = OptionButton3.Value
ListBox1.List(lindex, 9) = Format$(ListBox1.List(lindex, 9), myFormat(1)) = OptionButton3.Value
End If
End If
End Sub