Help needed on FORM Checkboxes...

Platem

New Member
Joined
Jul 9, 2011
Messages
5
I create a column of Checkboxes (FORM) at the end of rows of data as follows (WORKS FINE):
Code:
Sub DoCheckboxes()
    For Each cell In Range("O3:O60,O66:O123")
       With Sheets(1).CheckBoxes.Add(cell.Left + 2, cell.Top, 15, cell.Height)
           .LinkedCell = cell.Offset(, 0).Address(External:=True)
           .Interior.ColorIndex = xlClear
           .Caption = ""
           .OnAction = "Chk_Click"
       End With
    Next
End Sub
This function creates a border marker next to the first cell in the row when the corresponding box is checked (WORKS FINE):

Code:
Sub Chk_Click()
    Dim chk As CheckBox: Set chk = ActiveSheet.CheckBoxes(Application.Caller)
    
    If chk.Value = xlOn Then
        Cells(chk.TopLeftCell.Row, 1).Borders(xlEdgeRight).LineStyle = xlDouble
    Else
        Cells(chk.TopLeftCell.Row, 1).Borders(xlEdgeRight).LineStyle = xlDot
    End If
End Sub
Here's the problem:

After a SORT is performed, the data (including the checkboxes) is shifted around, but NOT the corresponding borders (Excel's SORT does not move cell borders)! So, I am trying to recreate the border markers (which were created with the above function) based on the current status of my 120 Checkboxes!

This is what I have:
Code:
Sub UpdateMarker()
    Dim i As Integer
    Dim chk As CheckBox: Set chk = ActiveSheet.CheckBoxes(Application.Caller)      '? not sure if this is right
    For i = 3 To 123
        If i < 61 Or i > 65 Then
            If chk.Value = "TRUE" Then                        '? need to check state of current checkbox
                Cells(i, 1).Borders(xlEdgeRight).LineStyle = xlDouble
            Else
                Cells(i, 1).Borders(xlEdgeRight).LineStyle = xlDot
            End If
        End If
    Next
End Sub
Help please! Project due...
icon6.gif
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
See if this macro does what you want...
Code:
Sub UpdateMarker()
    Dim i As Integer
    Dim chk As Shape
    For Each chk In Sheet1.Shapes
        If TypeName(chk.OLEFormat.Object) = "CheckBox" Then
            If chk.OLEFormat.Object.Value = 1 Then
                Cells(chk.TopLeftCell.Row, 1).Borders(xlEdgeRight).LineStyle = xlDouble
            Else
                Cells(chk.TopLeftCell.Row, 1).Borders(xlEdgeRight).LineStyle = xlDot
            End If
        End If
    Next
End Sub
 
Upvote 0
I'd punt on forms checkboxes and use Marlett checkboxes, which are on the same layer as the cells (they are cells) rather than the drawing layer. Then you can use conditional formatting to appliy the borders.

Search the board for many examples of Marlett checkboxes.

Or, you could use conditional formatting based on the linked cell to apply the formatting.
 
Upvote 0
@Rick

See if this macro does what you like...

Code:
Sub snb()
  For Each chk In Sheet1.CheckBoxes
    Cells(chk.TopLeftCell.Row, 1).Borders(xlEdgeRight).LineStyle = IIf(chk.Value = 1, xlDouble, xlDot)
  Next
End Sub
 
Upvote 0
@Rick

See if this macro does what you like...

Code:
Sub snb()
  For Each chk In Sheet1.CheckBoxes
    Cells(chk.TopLeftCell.Row, 1).Borders(xlEdgeRight).LineStyle = IIf(chk.Value = 1, xlDouble, xlDot)
  Next
End Sub
With the exception of your not having declared the chk variable, that is a fine modification to what I posted. (Hmm, I just noticed that I left in a declaration for an 'i' variable that I did not make use of in my originally posted code.) Although 120 checkboxes is probably not a large enough amount to make a noticeable difference, I did want to point out the IIF function executes much slower than its If..Then..Else equivalent, so the savings in space may not always be worth using it for that reason.
 
Upvote 0
Couldn't the formatting be done with conditional formatting?

Just base it on the linked cells of the checkboxes.
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,553
Members
452,928
Latest member
101blockchains

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top