Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Create Multiple checkboxes together

Posted on 2014-02-05
1
Medium Priority
?
195 Views
Last Modified: 2014-02-10
Hi,

I have the below macro which helps me create multiple checkboxes in a range and link those checkboxes to specific cells. Here is an example what exactly is happening with the below macro.

The macro ask for a range where I need to put in the checkboxes for ex I enter A5:A20 and then next it asks me to enter a column name to which the checkboxes are linked for ex I enter B then the macro links A5:A20 to B5:B20 respectively.

What I want to achieve is that I enter multiple ranges initially for I enter A5:A20,B5:B10 and then I enter C,D then it should link A5:A20 to C5:C20 and B5:B10 to D5:D10 respectively.

I hope i have provided all inputs. Kindly let me know incase any more input is required.

Thanks in advance.

Sub InsertCheckboxes()

    Dim myBox As CheckBox
    Dim myCell As Range

    Dim cellRange As String
    Dim cboxLabel As String
    Dim linkedColumn As String
     
    ' Enter range to insert check boxes in i.e. A5:A20
    cellRange = InputBox(Prompt:="Cell Range", Title:="Cell Range")
    ' Enter bound column letter
    linkedColumn = InputBox(Prompt:="Linked Column", Title:="Linked Column")
    ' Enter combobox caption, "" for no caption
    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)
                End With

                .NumberFormat = ";;;"
            End With

        Next myCell
    End With
End Sub

Open in new window

0
Comment
Question by:Vipin Kumar
1 Comment
 
LVL 53

Accepted Solution

by:
Rgonzo1971 earned 2000 total points
ID: 39835622
Hi,

pls try
Sub InsertCheckboxes()

    Dim myBox As CheckBox
    Dim myCell As Range

    Dim cellRange As String
    Dim cboxLabel As String
    Dim linkedColumn As String
     
    ' Enter range to insert check boxes in i.e. A5:A20
    cellRange = InputBox(Prompt:="Cell Range", Title:="Cell Range")
    ' Enter bound column letter
    linkedColumn = InputBox(Prompt:="Linked Column", Title:="Linked Column")
    ' Enter combobox caption, "" for no caption
    cboxLabel = InputBox(Prompt:="Checkbox Label", Title:="Checkbox Label")

    With ActiveSheet
        For Idx = 1 To .Range(cellRange).Areas.Count
        For Each myCell In .Range(cellRange).Areas(Idx)
            With myCell
                Set myBox = .Parent.CheckBoxes.Add(Top:=.Top, Width:=.Width, Left:=.Left, Height:=.Height)

                With myBox
                    ff = Split(linkedColumn, ",")(Idx - 1)
                    .LinkedCell = Split(linkedColumn, ",")(Idx - 1) & myCell.Row
                    .Caption = cboxLabel
                    .Name = "checkbox_" & myCell.Address(0, 0)
                End With

                .NumberFormat = ";;;"
            End With

        Next myCell
        Next
    End With
End Sub

Open in new window

Regards
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question