Option Explicit
Private Sub CommandButton1_Click()
Dim sh As Worksheet, sCurrency As String, lr As Long
Set sh = ThisWorkbook.Sheets("DATA")
lr = sh.Range("A" & Rows.Count).End(xlUp).Row + 1
With Me
sh.Range("A" & lr).Value = .TextBox4.Value
sh.Range("B" & lr).Value = .TextBox1.Value
sh.Range("C" & lr).Value = .ComboBox1.Value
sh.Range("D" & lr).Value = .TextBox2.Value
sh.Range("E" & lr).Value = .TextBox3.Value
sh.Range("F" & lr).Value = .TextBox5.Value
Select Case .ComboBox1.Value
Case "جنيه مصري": sCurrency = " ج.م. #,##0.00"
Case "دولار": sCurrency = "[$$-en-US]#,##0.00_ ;-[$$-en-US]#,##0.00 "
Case "يورو": sCurrency = "[$€-nl-BE] #,##0.00;[$€-nl-BE] -#,##0.00"
Case Else: sCurrency = Empty
End Select
If sCurrency <> Empty Then Union(sh.Range("D" & lr), sh.Range("F" & lr)).NumberFormat = sCurrency
sh.Range("A" & lr).Resize(1, 6).Borders.Value = 1
.TextBox1.Value = "": .TextBox2.Value = ""
.TextBox3.Value = "": .TextBox4.Value = ""
.TextBox5.Value = "": .ComboBox1.Value = ""
Call Refresh_Data_Click
.TextBox4.SetFocus
End With
End Sub
Private Sub CommandButton3_Click()
If Me.ListBox1.ListIndex < 0 Then MsgBox "لو سمحت اختار البيان المطلوب حذفه", vbCritical: Exit Sub
Dim sh As Worksheet, selected_row As Long
Set sh = ThisWorkbook.Sheets("DATA")
selected_row = Application.WorksheetFunction.Match(Me.ListBox1.List(Me.ListBox1.ListIndex, 0), sh.Range("A:A"), 0)
sh.Range("B" & selected_row).EntireRow.Delete
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.TextBox4.Value = ""
Me.ComboBox1.Value = ""
Call Refresh_Data_Click
End Sub
Private Sub CommandButton5_Click()
Unload Me
End
End Sub
Private Sub Refresh_Data_Click()
Dim lr As Long
Sheets("DATA").Activate
ListBox1.ColumnCount = 2
lr = Cells(Rows.Count, "A").End(xlUp).Row
With Me.ListBox1
.ColumnHeads = True
.RowSource = Range("A4:B" & lr).Address
End With
End Sub
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
If Me.ListBox1.List(Me.ListBox1.ListIndex, 0) <> "" Then
Me.TextBox1.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 1)
Me.TextBox4.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 0)
End If
End Sub
Private Sub TextBox2_AfterUpdate()
TextBox5.Value = Val(TextBox2.Value) * Val(TextBox3.Value)
End Sub
Private Sub TextBox3_AfterUpdate()
TextBox5.Value = Val(TextBox2.Value) * Val(TextBox3.Value)
End Sub
Private Sub UserForm_Activate()
Me.TextBox4.SetFocus
With Me.ComboBox1
.Clear
.AddItem "جنيه مصري"
.AddItem "دولار"
.AddItem "يورو"
.AddItem ""
End With
Call Refresh_Data_Click
End Sub