Change multiple control values based on opt selection

AndyEd

Board Regular
Joined
May 13, 2020
Messages
124
Office Version
  1. 365
Platform
  1. Windows
I have code to change multiple control values to "NA" when the value of an opt control is False.

Rather than coding for them individually, e.g.

VBA Code:
if opt2.value= true then
.txt1.value = "NA"
.txt2.value = "NA"
:
:

Is there a way that I can code for all controls together, such as placing them in an array for something?

Thank you for any assistance.
 

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.
This is just an example, but it shows how you can change the value of many checkboxes to the same value as long as the controls are named similarly.

VBA Code:
Public Nxt As Long

Private Sub CommandButton1_Click()
  
  Dim X As Long
  Dim Astr As String
  
  Nxt = Nxt + 1
  For X = 1 To 4
    Astr = "TextBox" & X
    Test_Frm.Controls(Astr).Value = Nxt
  Next X
  
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,958
Members
449,096
Latest member
Anshu121

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