Hello Guys !
I try to calculatie customer accounts based on userfrom . I put two formulas for each customers . the first formula will add from the first time when add new name and the second formual will be directly under first formula . so my goal copy data from userform to two sheets . to understand how could be . when I select optionbutton3 will change sheet name in label3 then should copy to sheet based on LABEL3 and when fill textbox1,2 should copy to column D,E and combobox1 to column B , optonbuttons1,2 names copy to column C . after select optionbutton3 or optionbutton4 to specify which sheet should copy to it I will select optionbutton1 and fill textbox1 and textbox2 is empty will copy textbox1 to column D and when select optionbutton2 and fill textbox2 and textbox1 is empty will copy textbox2 to column E .sometimes when I select optionbutton1 or optionbutton2 I will fill textbox1, textbox2 at the same time should copy to column D,E in the same row .
last thing based on the orginal code when add the name and the name is already existed then will add after the last row to give me the final result (this means should put data for the same name under each other of them )
Private Sub CommandButton1_Click()
Dim Valu As Double, Fnd As Range, rw As Long, nr As Long, col As Long
col = IIf(OptionButton1 = True, 4, 5)
With Sheets("" & Label3 & "")
nr = .Cells(.Rows.Count, 6).End(xlUp).Row + 1
Set Fnd = .Columns(2).Find(ComboBox1, .Columns(2).Cells(1), , , , xlPrevious)
If Fnd Is Nothing Then
Valu = 0
rw = nr
Else
Valu = .Range("F" & Fnd.Row).Value
rw = Fnd.Row + 1
End If
.Rows(rw).Insert: If rw = 2 Then .Rows(rw).Interior.Color = xlNone: .Rows(rw).Font.Bold = False
If col = 5 Then
.Range("B" & rw).Resize(, 5) = Array(ComboBox1, "not paid", TextBox1.Value, "", Valu + Val(TextBox1.Value))
Else
.Range("B" & rw).Resize(, 5) = Array(ComboBox1, "paid", "", TextBox2.Value, Valu - Val(TextBox2.Value))
End If
With .Cells(1).CurrentRegion
.Offset(1).Resize(.Rows.Count - 1).Columns(1).Value = Date
End With
End With
End Sub
Private Sub OptionButton3_Click()
If OptionButton3.Value = True And OptionButton4.Value = False Then
Label3.Caption = "SS"
End If
End Sub
Private Sub OptionButton4_Click()
If OptionButton4.Value = True And OptionButton3.Value = False Then
Label3.Caption = "TT"
End If
End Sub