problem copy values from optionbuttons.caption on userform to column

Alaa mg

Active Member
Joined
May 29, 2021
Messages
343
Office Version
  1. 2019
Hi
I face problem, the right way if I select optionbutton 5(CASH) then should copy to column C (CASH) and if I select optionbutton 6(not paid) then should copy to column C (not paid) .
the code just copy (not paid) whether select optionbutton5 or 6 , how can I correct this problem experts ?
note: the problem just in this part of code otherwise everything is ok .
VBA Code:
Private Sub CommandButton1_Click()

col = IIf(OptionButton3 = True, 4, 5)
With Sheets("" & Label30 & "")
     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)
     If col = 5 Then
       .Range("B" & rw).Resize(, 5) = Array(ComboBox1, OptionButton5.Caption, TextBox6.Value, TextBox7.Value, Valu + Val(TextBox6.Value) - Val(TextBox7.Value))
    Else
        .Range("B" & rw).Resize(, 5) = Array(ComboBox1, OptionButton6.Caption, TextBox6.Value, TextBox7.Value, Valu + Val(TextBox6.Value) - Val(TextBox7.Value))
    
    End If
    With .Cells(1).CurrentRegion
        .Offset(1).Resize(.Rows.Count - 1).Columns(1).Value = Date
    End With
    End With
End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
never mind ! the error in number of optionbutton . here is the solution after many tries and adjusting
VBA Code:
Private Sub CommandButton1_Click()

col = IIf(OptionButton5 = True, 4, 5)
With Sheets("" & Label30 & "")
     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)
     If col = 5 Then
       .Range("B" & rw).Resize(, 5) = Array(ComboBox1, "not paid", TextBox6.Value, TextBox7.Value, Valu + Val(TextBox6.Value) - Val(TextBox7.Value))
    Else
        .Range("B" & rw).Resize(, 5) = Array(ComboBox1, "cash", TextBox6.Value, TextBox7.Value, Valu + Val(TextBox6.Value) - Val(TextBox7.Value))
    
    End If
    With .Cells(1).CurrentRegion
        .Offset(1).Resize(.Rows.Count - 1).Columns(1).Value = Date
    End With
    End With
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,461
Messages
6,124,957
Members
449,200
Latest member
indiansth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top