Note that there are some explanatory texts on larger screens.

plurals
  1. POCycling through some checkboxes on my excel page
    text
    copied!<p>I am VERY new to VBA (and know of it only within excel).</p> <p>I am trying to cycle through some (but not all) checkboxes. They are currently named CheckBox1 through CheckBox15. Howe do I cycle through say for instance CheckBox5 through CheckBox10?</p> <p>I guess I am hoping there is a 'method' similar to 'CheckType' for controls that will allow me to check name?</p> <p>Here is what I have tried. Causes a Compile Error - Sub or Function not defined, and highlights Worksheet.</p> <pre><code>Private Sub BoxCheck() atLeastOneChecked = False For i = 2 To 4 If Worksheets("ActiveX").Controls("Checkbox" &amp; i).Value = True Then atLeastOneChecked = True End If Next i End Sub </code></pre> <p>While the above doesnt work, what is below does:</p> <pre><code>Private Sub BoxCheck() atLeastOneChecked = False For i = 1 To 2 If Sheet2.CheckBox2.Value = True Then atLeastOneChecked = True End If Next i End Sub </code></pre> <p>Of course, the loop has no affect on the outcome, but it compiles and atLeastOneChecked turns from False to True when Checkbox2 is True. Note that Sheet2 has been named ActiveX. I clearly don't understand how Worksheet and Controls work. Could someone help?</p> <p>After fixing the error described below, this still won't work. I simplified to the following:</p> <pre><code>Private Sub BoxCheck() Dim ole As OLEObject atLeastOneChecked = False Set ole = Sheets("ActiveX").OLEObjects("Checkbox2") If ole.Value = True Then atLeastOneChecked = True End If End Sub </code></pre> <p>This doesn't work. It fails at:</p> <pre><code>If ole.Value = True Then </code></pre> <p>The error states: Object Doesn't support this property or method</p> <p>This is true for OLEObjects, but not for Checkboxes. When I look at the properties of ole, I see that its Object property is set to Object/Checkbox and that this Object has a value. I guess that is what I should be referencing in my if statement, but I don't know how.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload