Excel VBA-如果单元格包含复选框,则单击 [英] Excel VBA - Ckeck if cell contains a checkbox

查看:72
本文介绍了Excel VBA-如果单元格包含复选框,则单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下脚本将复选框添加到一系列单元格中.我想通过检查单元格是否已经包含复选框来增强此功能,如果不包含,则不要在该单元格中添加新的复选框,即,如果该范围中的单元格尚未包含复选框,则仅向该单元格中添加一个复选框

I am using the following script to add checkboxes to a range of cells. I would like to enhance this by checking if the cell already contains a checkbox and if it does then do not add a new checkbox in the cell, ie only add a check box to a cell in the range if it does not already contain a checkbox.

    LRow = ActiveSheet.Range("D" & Rows.Count).End(xlUp).Row

For cell = 10 To LRow
        CLeft = Cells(cell, "R").Left
        CTop = Cells(cell, "R").Top
        CHeight = Cells(cell, "R").Height
        CWidth = Cells(cell, "R").Width
        ActiveSheet.CheckBoxes.Add(CLeft, CTop, CWidth, CHeight).Select
        With Selection
            .Caption = ""
            .Value = xlOff
            .Display3DShading = False
        End With
Next cell

推荐答案

使用此功能检查范围是否包含复选框:

Use this function to check if a range contains a checkbox:

Public Function HasCheckbox(rng As Range) As Boolean
    For Each CB In ActiveSheet.CheckBoxes
        If Not Application.Intersect(rng, CB.TopLeftCell) Is Nothing Then
            HasCheckbox = True
            Exit Function
        End If
    Next CB
    HasCheckbox = False
End Function

这篇关于Excel VBA-如果单元格包含复选框,则单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆