jeudi 12 octobre 2017

How to automatically load checkbox if cell full?

I'm trying to excel in creating a checkbox automatically if the cell in column A has a data. Also if from column A have data from A: 5 to A: 11 there should be 6 checkboxes, one for each full cell. I have tried to adapt the following macro that takes the changes in column A but I have failed successfully.

Private Sub Worksheet_Change(ByVal Target As Range) Dim chkbox As CheckBox Dim cell As Range

If Not Intersect(Target, Range("A10:A1000")) Is Nothing Then
    For Each cell In Intersect(Target, Range("A10:A1000"))
        If Not IsEmpty(cell.Value) Then
            'If the cell is NOT empy, I should add a checkbox, to the right of the cell without text
            Set chkbox = ActiveSheet.CheckBoxes.Add(cell.Left, cell.Top, cell.Width, cell.Height)
            With chkbox
                .Text = ""
            End With
        Else
            For Each chkbox In ActiveSheet.CheckBoxes
                If Not Intersect(cell, chkbox.TopLeftCell) Is Nothing Then
                    chkbox.Delete
                End If
            Next chkbox
        End If
    Next cell
End If

Call LinkCheckBoxes

End Sub

thanks for your help




Aucun commentaire:

Enregistrer un commentaire