+ Reply to Thread
Results 1 to 15 of 15

How to copy checkboxes down a column?

Hybrid View

  1. #1
    Registered User
    Join Date
    05-24-2008
    Location
    San Mateo, Ca
    Posts
    44

    How to copy checkboxes down a column?

    I figured out how to insert a checkbox into cell I4. I'd like to drag/copy the cell all the way down the column, but it doesn't work this way. How can I do that without individually copy/pasting into each cell?

    Better yet, is there a way to make a check box appear only if there is content in the row? This is a spread sheet where I add one or two rows per day. For example, if there is content in B25, make a check box appear in I25? That would help keep the spreadsheet clean.

    Thanks,

    Dan

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello earthtodan,

    Yes it can be done. However, I need to know where the CheckBox came from, Forms tool bar or Control Toolbox. Also are there any macros associated with these check boxes? Any special formatting of font size, color, etc? Do they display any text?

    Sincerely,
    Leith Ross

  3. #3
    Registered User
    Join Date
    05-24-2008
    Location
    San Mateo, Ca
    Posts
    44
    I did it using the forms toolbar, although I don't really know the difference. I'll do it whichever way is best. I don't know how to get the checkboxes to "stick" using the control toolbox.
    There is no special formatting associated with them or any code. They are in a column titled "Oversold", and they get checked if a project (row) is oversold. They are going to be counted in a COUNT IF TRUE formula.

    Dan

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Dan,

    Here are the macros to add the check boxes into column "I" if the cell in column "B" isn't empty.
    Sub AddCheckBoxToCell(Ref_Cell As Range)
        
      Dim ChkBox As CheckBox
      Dim N As Double
      
        With Ref_Cell.Cells(1, 1)
          refLeft = .Left
          refTop = .Top
          refHeight = .Height
        End With
          
          Set ChkBox = ActiveSheet.CheckBoxes.Add(10, 10, 15, 12)
          
          N = (refHeight - ChkBox.Height) / 2#
          
          With ChkBox
            .Caption = ""
            .Top = refTop + N
            .Left = refLeft
            .OnAction = ""
          End With
        
    End Sub
    
    Sub AddCheckBoxes()
    
      Dim BoxCol As Variant
      Dim CtrlCol As Variant
      Dim LastRow As Long
      Dim R As Long
      Dim StartRow As Long
      
        BoxCol = "I"     'Column where Check Box is inserted
        CtrlCol = "B"    'Column that controls if Check Box is inserted
        StartRow = 1
        LastRow = Cells(Rows.Count, CtrlCol).End(xlUp).Row
        
            For R = StartRow To LastRow
              If Cells(R, CtrlCol) <> "" Then
                AddCheckBoxToCell Cells(R, BoxCol)
              End If
            Next R
                
    End Sub
    Adding the Macro
    1. Copy the macro above pressing the keys CTRL+C
    2. Open your workbook
    3. Press the keys ALT+F11 to open the Visual Basic Editor
    4. Press the keys ALT+I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Paste the code by pressing the keys CTRL+V
    7. Make any custom changes to the macro if needed at this time
    8. Save the Macro by pressing the keys CTRL+S
    9. Press the keys ALT+Q to exit the Editor, and return to Excel.

    To Run the Macro...
    To run the macro from Excel, open the workbook, and press ALT+F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

    Sincerely,
    Leith Ross

  5. #5
    Registered User
    Join Date
    05-24-2008
    Location
    San Mateo, Ca
    Posts
    44
    Wow, thanks for all that code. I'll test it out as soon as I'm not supposed to be working.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Checkboxes from the Forms toolbox or Control Toolbar are on a different layer of the sheet than cells, so it's easy to mangle their associations. 'Twere I you, I'd use Marlett checkboxes. They are cells with a double-click behavior implemented in about five lines of VBA. A search will turn up many examples.

  7. #7
    Registered User
    Join Date
    01-22-2012
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: How to copy checkboxes down a column?

    I know this is an old thread but how do you center the checkbox in the cell? I am very new to VBA.



    Quote Originally Posted by Leith Ross View Post
    Hello Dan,

    Here are the macros to add the check boxes into column "I" if the cell in column "B" isn't empty.
    Sub AddCheckBoxToCell(Ref_Cell As Range)
        
      Dim ChkBox As CheckBox
      Dim N As Double
      
        With Ref_Cell.Cells(1, 1)
          refLeft = .Left
          refTop = .Top
          refHeight = .Height
        End With
          
          Set ChkBox = ActiveSheet.CheckBoxes.Add(10, 10, 15, 12)
          
          N = (refHeight - ChkBox.Height) / 2#
          
          With ChkBox
            .Caption = ""
            .Top = refTop + N
            .Left = refLeft
            .OnAction = ""
          End With
        
    End Sub
    
    Sub AddCheckBoxes()
    
      Dim BoxCol As Variant
      Dim CtrlCol As Variant
      Dim LastRow As Long
      Dim R As Long
      Dim StartRow As Long
      
        BoxCol = "I"     'Column where Check Box is inserted
        CtrlCol = "B"    'Column that controls if Check Box is inserted
        StartRow = 1
        LastRow = Cells(Rows.Count, CtrlCol).End(xlUp).Row
        
            For R = StartRow To LastRow
              If Cells(R, CtrlCol) <> "" Then
                AddCheckBoxToCell Cells(R, BoxCol)
              End If
            Next R
                
    End Sub
    Adding the Macro
    1. Copy the macro above pressing the keys CTRL+C
    2. Open your workbook
    3. Press the keys ALT+F11 to open the Visual Basic Editor
    4. Press the keys ALT+I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Paste the code by pressing the keys CTRL+V
    7. Make any custom changes to the macro if needed at this time
    8. Save the Macro by pressing the keys CTRL+S
    9. Press the keys ALT+Q to exit the Editor, and return to Excel.

    To Run the Macro...
    To run the macro from Excel, open the workbook, and press ALT+F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

    Sincerely,
    Leith Ross

  8. #8
    Registered User
    Join Date
    08-30-2013
    Location
    St. Louis
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: How to copy checkboxes down a column?

    This is very helpful but I have a few questions:

    Note: All questions are meant to be included in the macro.

    How do I make the size wider so the "Text" next to the box will all shows up?

    Can the "Cell Link" be included in the Macro to another column?

  9. #9
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,049

    Re: How to copy checkboxes down a column?

    perpstudent, welcome to the forum

    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1