简体   繁体   中英

Automatic selection of checkbox in excel VBA

I have maintained a excel sheet where in column A there are list of all parameters for a particular product, and again in column D there are few parameters which i require to choose from set of all the parameters in column A.

Is it possible in vba to trigger a click event where it should compare between column A and column D and select the checkboxes automatically if it finds the parameter.

在此处输入图片说明

Any help is appreciated!

Ok What you can do is this:

Put the checkboxes (make sure that they are format control checkboxes) in Column C. (Be sure that the Checkbox is completely in the cell)

Post this in the Worksheetmodul:

Private Sub Worksheet_Change(ByVal Target As Range)

Dim chk As CheckBox
Dim check As Boolean
Dim rng As Range

For Each chk In ActiveSheet.CheckBoxes

    Set rng = Range("D:D").Find(what:=chk.TopLeftCell.Offset(0, -2).Value, _
    LookIn:=xlValues, _
    lookat:=xlWhole, _
    searchorder:=xlByRows, _
    searchdirection:=xlNext, _
    MatchCase:=False)

    If Not rng Is Nothing Then

        chk.Value = True

    End If

Next chk

End Sub

Every time a value is changed in the worksheet, the sub is triggered.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM