跳到主要内容

如何在Excel中使用复选框突出显示单元格或行?

如下面的屏幕截图所示,您需要使用复选框突出显示行或单元格。 选中复选框后,指定的行或单元格将自动突出显示。 但是如何在Excel中实现呢? 本文将向您展示两种实现方法。

使用条件格式复选框突出显示单元格或行
用带有VBA代码的复选框突出显示单元格或行


使用条件格式复选框突出显示单元格或行

您可以创建条件格式规则,以在Excel中使用复选框突出显示单元格或行。 请执行以下操作。

将所有复选框链接到指定的单元格

1.您需要通过单击将复选框手动逐一插入到单元格中 开发商 > 插页 > 复选框 (表单控制).

2.现在,复选框已插入到I列中的单元格。请选中I1中的第一个复选框,输入公式 = $ J1 进入编辑栏,然后按 输入 键。

Tips::如果您不想让相邻单元格中的值与复选框相关联,则可以将该复选框链接到另一个工作表的单元格,例如 = Sheet3!$ E1.

2.重复步骤1,直到所有复选框都链接到相邻的单元格或另一个工作表中的单元格。
备注:所有链接的单元格应该是连续的,并且位于同一列中。

创建条件格式设置规则

现在,您需要按以下步骤创建条件格式设置规则。

1.选中需要用复选框突出显示的行,然后单击 条件格式 > 新规则 在下面 主页 标签。 看截图:

2.在 新格式规则 对话框,您需要:

2.1选择 使用公式来确定要格式化的单元格 在选项 选择规则类型 框;

2.2输入公式 = IF($ J1 = TRUE,TRUE,FALSE) 格式化此公式为真的值 框;
      Or = IF(Sheet3!$ E1 = TRUE,TRUE,FALSE) 如果复选框链接到另一个工作表。

2.3点击 格式 按钮为行指定突出显示的颜色;

2.4点击 OK 按钮。 看截图:

备注: 在公式, $ J1 or $ E1 是复选框的第一个链接单元格,并确保单元格引用已更改为绝对列(J1> $ J1 or E1 > $E1).

现在,将创建条件格式设置规则。 选中复选框时,相应的行将自动突出显示,如下图所示。


用带有VBA代码的复选框突出显示单元格或行

以下VBA代码还可以帮助您在Excel中使用复选框突出显示单元格或行。 请执行以下操作。

1.在工作表中,您需要突出显示带有复选框的单元格或行。 右键点击 工作表标签 并选择 查看代码 从右键菜单中打开 Microsoft Visual Basic应用程序 窗口。

2.然后将下面的VBA代码复制并粘贴到“代码”窗口中。

VBA代码:在Excel中用复选框突出显示行

Sub AddCheckBox()
Dim xCell As Range
Dim xRng As Range
Dim I As Integer
Dim xChk As CheckBox
On Error Resume Next
InputC:
    Set xRng = Application.InputBox("Please select the column range to insert checkboxes:", "Kutools for Excel", Selection.Address, , , , , 8)
If xRng Is Nothing Then Exit Sub
If xRng.Columns.Count > 1 Then
    MsgBox "The selected range should be a single column", vbInformation, "Kutools fro Excel"
    GoTo InputC
Else
    If xRng.Columns.Count = 1 Then
        For Each xCell In xRng        
            With ActiveSheet.CheckBoxes.Add(xCell.Left, _
               xCell.Top, xCell.Width = 15, xCell.Height = 12)
               .LinkedCell = xCell.Offset(, 1).Address(External:=False)
               .Interior.ColorIndex = xlNone
               .Caption = ""
               .Name = "Check Box " & xCell.Row
            End With    
            xRng.Rows(xCell.Row).Interior.ColorIndex = xlNone                  
        Next        
    End If    
    With xRng    
     .Rows.RowHeight = 16    
    End With   
    xRng.ColumnWidth = 5#    
    xRng.Cells(1, 1).Offset(0, 1).Select    
    For Each xChk In ActiveSheet.CheckBoxes   
      xChk.OnAction = ActiveSheet.Name + ".InsertBgColor"      
    Next
End If
End Sub

Sub InsertBgColor()
Dim xName As Integer
Dim xChk As CheckBox
For Each xChk In ActiveSheet.CheckBoxes 
  xName = Right(xChk.Name, Len(xChk.Name) - 10) 
  If (xName = Range(xChk.LinkedCell).Row) Then   
   If (Range(xChk.LinkedCell) = "True") Then   
    Range("A" & xName, Range(xChk.LinkedCell).Offset(0, -2)).Interior.ColorIndex = 6    
   Else    
    Range("A" & xName, Range(xChk.LinkedCell).Offset(0, -2)).Interior.ColorIndex = xlNone  
   End If  
  End If
Next
End Sub

3。 按 F5 键来运行代码。 (备注:您应将光标置于代码的第一部分以应用F5键)在弹出窗口中 Kutools for Excel 对话框,请选择要插入的范围复选框,然后单击 OK 按钮。 在这里,我选择范围I1:I6。 看截图:

4.然后将复选框插入到选定的单元格中。 选中任何一个复选框,对应的行将自动突出显示,如下图所示。


相关文章:

最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。  单击此处获取您最需要的功能...

产品描述


Office Tab 为 Office 带来选项卡式界面,让您的工作更加轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!
Comments (3)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
This is a horrendous article. It lacks a lot of information and steps. If you follow this article verbatim it will not end in the result you are seeking.

Essentially the article is saying to have 2 columns where the checkboxes are linked to adjacent columns to enter in values which are then used for conditional formats. No one wants to have values associated in adjacent cells to checkboxes. Lastly, if this is the route you're going you're not linking checkboxes to conditional formats, you are linking checkboxes to cell values which are then in turn associated to conditional formats.

It is easier to just use icons instead of checkboxes (use the green checkmark icon) and create the conditional formats for a value of 1 or 0. If cell = 1 then it will replace the value with the icon and highlight your row. To accomplish this you use 2 conditional formats on your table.

Top left of table is B4, bottom right of table is L28

1st conditional format:
USE A FORMULA TO DETERMINE WHICH CELLS TO FORMAT
Formula: =$B4=1
Format: fill
Applies to: =$B4:$L28

2nd conditional format:
FORMAT CELLS BASED ON THEIR VALUES
Icon Set Custom
SHOW ICON ONLY (check this box off)
First icon (green checkmark) when value is > = 1 (type: number)
Second icon (no icon) when value is > = -1 (type: number)
Third icon (no icon) when < -1

Now, when I enter a 1 in B4 or any of the B column cells, it will highlight the entire row for me and replace the "1" with a checkmark.

BUILT-IN TEMPLATE WITH THIS FORMATTING:
1) Open Excel, search for a new template. Enter "Inventory" as the search term
2) Select the template titled "Inventory list with highlighting"
3) Highlight the first row of the table, open conditional formats to manage/edit. You will see the 2nd and 3rd formats are for highlights and the icon in the B column. You can change the icon to whatever you want. Remove the first format if you don't want the strikeout options from the Discontinued column.
This comment was minimized by the moderator on the site
I have a question about the initial step of linking the checkbox to a true/false.

1. Select the first check box in I1, enter formula =$J$1 into the formula bar, and then press the Enter key.

2. Repeat step 1 until all check boxes are linked to the adjacent cells.

For the repeat, does it have to be done for each cell or can you get the drag down to autofill? Right now, when I drag down the corner box it will autofill with =$J$1 for everything so that if I check one box, every box is checked. How can I fix this without manually linking each checkbox?
This comment was minimized by the moderator on the site
Hi,
The Fill Handle can't help in this case. You need to manually link each checkbox to its adjacent cell.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations