title: Dynamically Checking for Checkboxes with the same name as Worksheets -VBA Excel
body: <p>I am on excel, I have about 30 UserForm checkboxes, each of the checkboxes are located on a page called "Summary" in a big column. Each of which corresponds to a worksheet. I am attempting to loop through these checkboxes to see which are ticked and not ticked. I have put some code within a loop of all worksheets, this is the bit that is not working:</p>
  
  <pre><code>  Private Sub Run_Click()
  Dim SummaryFirstBlankRow As Integer
  Dim LastRow As Integer
  Dim LastRowH As Integer
  Dim rng As Range
  Dim SumOfHours As Variant
  Dim EndLoop As Boolean
  Dim DupeRowNo As Integer
  Dim RowNo2 As Integer
  Dim ClearContent As Boolean
  Dim cbtrue As Boolean
  Dim ws As Worksheet
  
  
  cbtrue = False
      For Each ws In ActiveWorkbook.Worksheets
  
  
  
          LastRowH = ws.Cells(Rows.Count, 8).End(xlUp).Offset(1, 0).Row
  
  
      'If ActiveWorkbook.Sheets("Summary").CheckBoxes(ws.name).Value = False Then ' looks to see if ws.names' checkbox is checked or not
       '               ClearContent = True 'if not checked, sets clear content to true
      'End If
  
      For Each CheckBox In Sheets("Summary").CheckBoxes
          If CheckBox.name = ws.name Then
              If CheckBox.Value = False Then
                  ClearContent = True
              End If
          End If
      Next CheckBox
          If ClearContent = True Then
              For c = 1 To LastRowH   'if not checked, looks on current worksheet (within loop) and if any "Y" or "y" vals, clears them
                  If ws.Range("H" &amp; c).Value = "Y" Or ws.Range("H" &amp; c).Value = "y" Then
                      ws.Range("H" &amp; c).ClearContents
                  End If
              Next
          End If
      ...
  </code></pre>
  
  <p>cbtrue is just a variable to see if the checkbox exists, hence if it does it will then go to the if statement, at which point it will determine whether that checkbox is ticked or not, depending on this it saves the ClearContent variable (which I use later on in the code).</p>
  
  <p>The problem is when it comes to 'Shapes("ws.Name")', ws.name is simply the name of the worksheet on each loop. So on the first round of the loop, it will be "Summary"... However, I think it is physically searching for the sheet "ws.name" which obviously doesn't exist. I have tried removing it from the quotation marks and also various other methods such as 'Checkboxes("ws.Name")' but it seems they all have the same problem.</p>
  
  <p>I am posting to see if someone could offer me another method, or perhaps show me where I have gone wrong, as I think I am not fully understanding the syntax.</p>
  
  <p>Any Help is appreciated. Thanks in advance :)</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I have changed the code with the help of @Xabier (I have added in an extra if statement to ensure that the CheckBox has the same name as the worksheet. I am now getting no errors, but when i run it, it isn't clearing the contents of any of the cells i requested. I cannot seem to spot why it is doing this, If anyone could spot it and let me know, that'd be great. Thanks :) </p>