worksheet change event to add CheckBox and edit Caption

padadof2

New Member
Joined
Jan 11, 2010
Messages
44
I'm trying to set up a worksheet change event that creates a checkbox in column 1 if the cell in column 8 changes. I am able to get a checkbox, but I can't get the caption to change. I'm able to do it using this code, but I don't want to do it manually. Thank you in advance for any pointers and help

VBA Code:
Dim c As Range
    For Each c In Selection
        Dim cb As checkbox
        Set cb = ActiveSheet.CheckBoxes.Add(c.Offset(0, -7).Left, _
                                    c.Offset(0, -7).Top, _
                                    c.Offset(0, -7).Width, _
                                    c.Offset(0, -7).Height)
        With cb
            .Caption = "Proposal Sent"
            .Value = xlOff
            .Display3DShading = False
        End With
    Next
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
I figured it out.
Here is the code in case someone else has the same issue

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rngWatch As Range
    Dim cb As checkbox

    Set rngWatch = Range("H:H")

    If Intersect(rngWatch, Target) Is Nothing Then Exit Sub

    If Target.Count > 1 Then Exit Sub

    Set cb = ActiveSheet.CheckBoxes.Add(Target.Offset(0, -7).Left, _
        Target.Offset(0, -7).Top, _
        Target.Offset(0, -7).Width, _
        Target.Offset(0, -7).Height)
    
    With cb
        .Caption = "Proposal Sent"
        .Value = xlOff
        .Display3DShading = False
    End With

End Sub
 
Upvote 0
Alternatively you could use ...

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Target.CountLarge > 1 Then
        If Not Application.Intersect(Target, Columns("H:H")) Is Nothing Then
            Dim cb As CheckBox
            Set cb = Target.Parent.CheckBoxes.Add(10, 10, 10, 10)
            With Target.Offset(0, -7)
                cb.Caption = "Proposal Sent"
                cb.Left = .Left
                cb.Top = .Top
                cb.Height = .Height
                cb.Width = .Width
                ' cb.Width = 20 + (Len(cb.Caption) * 4)   ' << adjust width so text of caption is likely to fit
            End With
        End If
    End If
End Sub
 
Upvote 0
Alternatively you could use ...

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Target.CountLarge > 1 Then
        If Not Application.Intersect(Target, Columns("H:H")) Is Nothing Then
            Dim cb As CheckBox
            Set cb = Target.Parent.CheckBoxes.Add(10, 10, 10, 10)
            With Target.Offset(0, -7)
                cb.Caption = "Proposal Sent"
                cb.Left = .Left
                cb.Top = .Top
                cb.Height = .Height
                cb.Width = .Width
                ' cb.Width = 20 + (Len(cb.Caption) * 4)   ' << adjust width so text of caption is likely to fit
            End With
        End If
    End If
End Sub
thank you! I will try them both. Appreciate it.
 
Upvote 0
You're welcome and thanks for letting me know (y)
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,219
Members
452,619
Latest member
Shiv1198

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