Forum

New to VBA.. Having...
 
Notifications
Clear all

New to VBA.. Having trouble adding in a Option Button

2 Posts
2 Users
0 Reactions
114 Views
(@leslie-smith)
Posts: 9
Eminent Member
Topic starter
 

I am having a feeling that I am overthinking this one. 

I started out with a dropdown box but I thought and option box might be quicker; one less click.  

 

If Trim(frm.Range("H14").Value) <> "Yes" And Trim(frm.Range("H14").Value) <> "No" Then

  ' If .optYes.Value Then Trim(frm.Range("H14").Value) = "Yes" And .optNo.Value Trim(frm.Range("H14").Value) = "No"
  MsgBox "Please select valid Choice.", vbOKOnly + vbInformation, "Avl Replen"
  frm.Range("H14").Select
  frm.Range("H14").Interior.Color = vbRed
  Validate = False
  Exit Function
End If

 
Posted : 27/08/2020 7:12 pm
Philip Treacy
(@philipt)
Posts: 1630
Member Admin
 

Hi Leslie,

I'd switch to using regular form controls rather than ActiveX.

You can use this to test the buttons

If frm.OptionButtons("YesBtn").Value = xlOff And frm.OptionButtons("NoBtn").Value = xlOff Then

but by setting the default value of both buttons to Checked (Design Mode -> Format Control -> Control -> Checked) one of the buttons will always be selected by default so the test in itself becomes redundant.

see attached.

regards

Phil

 
Posted : 27/08/2020 11:11 pm
Share: