Results 1 to 5 of 5

Thread: help required with VBA code

  1. #1

    help required with VBA code



    Register for a FREE account, and/
    or Log in to avoid these ads!

    • I have checkboxes on a worksheet in two separate columns as follows P4:P16 & Q4:Q16. I use two macros one to un tick all boxes and one to enable all boxes. When I use both the clear and enable code it clears all checkboxes or enables all. I would like two different macro one to clear P4:P16 and also to enable P416

      I would appreciate any help with this? The code I used is as follows:



    • to Un Tick:

      Code:
      Sub ClearChecks()
       Dim CB As Object
       For Each CB In ActiveSheet.CheckBoxes
       CB.Value = xlOff
       Next CB
       End Sub

      • To Enable checkboxes:

        Code:
        Sub EnableChecks()
         Dim CB As Object
         For Each CB In ActiveSheet.CheckBoxes
         CB.Value = xlOn
         Next CB
        
         End Sub






    Last edited by microhunt; 2014-11-16 at 03:23 PM.

  2. #2
    Magician NoS's Avatar
    Join Date
    Jan 2013
    Location
    British Columbia
    Posts
    825
    Articles
    0
    Excel Version
    Excel 2010
    try changing
    Code:
    CB.Value = xlOff
    to
    Code:
    If CB.TopLeftCell.Column = 16 Then CB.Value = xlOff

  3. #3
    Conjurer snb's Avatar
    Join Date
    May 2013
    Posts
    376
    Articles
    0
    Excel Version
    2020
    Integrated into 1:


    Code:
    Sub M_snb()
      For Each CB In ActiveSheet.CheckBoxes
        CB.Value = not cb.value
      Next
    End Sub

  4. #4
    Super Moderator Bob Phillips's Avatar
    Join Date
    Mar 2011
    Posts
    1,841
    Articles
    0
    Excel Version
    O365
    Another way similar to NoS' might be test for the selected column


    Code:
            If CB.TopLeftCell.Column = ActiveCell.Column Then CB.Value = xlOff

  5. #5

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •