Results 1 to 6 of 6

one macro to run multiple checkboxes

Threaded View

  1. #1
    Registered User
    Join Date
    09-11-2012
    Location
    Rockville, MD
    MS-Off Ver
    Excel 2003
    Posts
    47

    Question one macro to run multiple checkboxes

    I have a worksheet I am developing that will eventually have about 3,000 checkboxes. I found a macro posted online to create the checkboxes, which works great. I also have a macro which will run an individual checkbox to do the following to the adjacent cell if the checkbox is clicked: change the cell value, lock the cell, and format the cell. Both sets of code work great. The problem is I will have to create 3,000 macros with 3,000 different names and open 3,000 checkboxes to assign the appropriate macro. I want to assign one macro to every checkbox as it is created that assigns a universal macro which simply says, if this checkbox is clicked, then make changes to the adjacent cell. I added an .onAction command to the below insertCheckboxes code to assign a macro called CheckBoxUniversal_Click. That works, now I need to create the code for CheckBoxUniversal_Click which will tell excel to make changes to the adjacent cell. Thoughts?

    Sub insertCheckboxes()
       Dim myBox As CheckBox
       Dim myCell As Range
       Dim cellRange As String
      Dim cboxLabel As String
      Dim linkedColumn As String
     
      cellRange = InputBox(Prompt:="Cell Range", _
        Title:="Cell Range")
     
      linkedColumn = InputBox(Prompt:="Linked Column", _
        Title:="Linked Column")
     
      cboxLabel = InputBox(Prompt:="Checkbox Label", _
        Title:="Checkbox Label")
     
      With ActiveSheet
        For Each myCell In .Range(cellRange).Cells
          With myCell
            Set myBox = .Parent.CheckBoxes.Add(Top:=.Top, _
              Width:=.Width, Left:=.Left, Height:=.Height)
     
            With myBox
              .LinkedCell = linkedColumn & myCell.Row
              .Caption = cboxLabel
              .Name = "checkbox_" & myCell.Address(0, 0)
              .onAction = "CheckBoxUniversal_Click"
            End With
     
            .NumberFormat = ";;;"
                  
          End With
     
        Next myCell
      End With
    End Sub
    Last edited by jeffreybrown; 09-11-2012 at 03:51 PM. Reason: Added code tags for new user...please do so next time

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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