跳到主要内容

如何将复选框链接到Excel中的多个单元格?

将复选框链接到多个相对单元格可以帮助您快速,轻松地进行一些计算,而仅需要对已选中或未选中的单元格进行求和,计数或平均。 但是,您是否曾经尝试在工作表中一次将复选框链接到多个单元格?

一对一地将复选框链接到多个单元格

使用VBA代码一次将复选框链接到多个单元


箭头蓝色右气泡 一对一地将复选框链接到多个单元格

实际上,要将复选框链接到特定的单元格,您可以应用一个简单的公式来手动链接它们。

1。 在工作表中插入复选框后,要选中该复选框,请按 按Ctrl 键,然后单击要链接到其他单元格的第一个复选框。

2.然后在编辑栏中,键入等号 =,然后单击要将复选框链接到的一个单元格,例如B2,请参见屏幕截图:

DOC-LINK-MULTIPE-CHECKBOXES-1

3。 然后按 输入 键,现在,当您选中此复选框时,将显示链接的单元格 TRUE,如果取消选中它将显示 FALSE,请参见屏幕截图:

DOC-LINK-MULTIPE-CHECKBOXES-2

4。 重复上述步骤,一个接一个地链接其他复选框。


箭头蓝色右气泡 使用VBA代码一次将复选框链接到多个单元

如果需要将成千上万的复选框链接到其他单元格,则第一种方法将无法有效工作,要将它们一次链接到多个单元格,可以应用以下VBA代码。 请这样做:

1。 转到带有复选框列表的工作表。

2。 按住 ALT + F11 键打开 Microsoft Visual Basic for Applications窗口.

3。 点击 插页 > 模块,然后将以下代码粘贴到 模块窗口.

VBA代码:一次将复选框链接到多个单元

Sub LinkChecks()
'Update by Extendoffice
Dim xCB
Dim xCChar
i = 2
xCChar = "B"
For Each xCB In ActiveSheet.CheckBoxes
If xCB.Value = 1 Then
    Cells(i, xCChar).Value = True
Else
    Cells(i, xCChar).Value = False
End If
xCB.LinkedCell = Cells(i, xCChar).Address
i = i + 1
Next xCB
End Sub

4。 然后按 F5 键以运行此代码,活动工作表中的所有复选框均已链接到单元格,当您选中该复选框时,其相对单元格将显示 TRUE,如果清除复选框,则链接的单元格应显示 FALSE,请参见屏幕截图:

DOC-LINK-MULTIPE-CHECKBOXES-3

备注:在上面的代码中, I = 2, 号码 2 是复选框的起始行,并且字母 B 是您需要将复选框链接到的列位置。 您可以根据需要更改它们。


相关文章:

如何在Excel中使用单个复选框选择所有复选框?

如何在Excel中快速插入多个复选框?

如何在Excel中快速删除多个复选框?

最佳办公生产力工具

🤖 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 (17)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Will this work when I try to sort Alphabetically? I've found that when I sort from A-Z, the check boxes do not follow the cells they were originally next to. Will your method help? Thank you!
This comment was minimized by the moderator on the site
My problem is: I am creating a to do list with daily habits. I want to be able to make statistics from it using the true and false from checking the box linked to a cell but do not want to individually do it, but when i use the code nothing happens?
This comment was minimized by the moderator on the site
Hello, Gregor,
The VBA code works well in my workbook.
You can upload your file here, so that we can check where the problem is.
Thank you!
This comment was minimized by the moderator on the site
Здравствуйте.
Подскажите. Возможно ли суммирование чисел в ячейках по установке флажка?

https://drive.google.com/file/d/1qmEnngPDdgWTISJETJ44IkxG-MABfqhh/view?usp=sharing[/img][/b][/u][/b

В ячейке F3 скрыто число 2 а в ячейке G3 скрыто число 0,3, можно ли сделать так чтоб при установки галочки в ячейке Q3 вычислялась сумма.
Сумма вычислений только на строку в диапазоне F3-P3
This comment was minimized by the moderator on the site
great thread and it works for me.
BUT, I need to save the TRUE/FALSE data to another sheet. What is the VBA to save it to another sheet other than the active one?
This comment was minimized by the moderator on the site
How about if you have some empty rows in ColumnA (as per your example) in between checkboxes? Using the above code it gets the linked cells wrong if there are empty rows because it does not skip them. Interested to see the solution
This comment was minimized by the moderator on the site
Did u find any solution for this? Same problem
This comment was minimized by the moderator on the site
Sub LinkCheckBoxes()

Dim chk As CheckBox

Dim lCol As Long

lCol = 1 'number of columns to the right for link



For Each chk In ActiveSheet.CheckBoxes

With chk

.LinkedCell = _

.TopLeftCell.Offset(0, lCol).Address

End With

Next chk



End Sub
This comment was minimized by the moderator on the site
Hello! Nice post about the VBA... but what if there are 3 columns that has checkboxes that needs to be linked in three other columns as well? Let's say columns B, C, and D has checkboxes and should be linked to columns H, I, and J respectively.
This comment was minimized by the moderator on the site
Hi, Having same problem - Have you found out how to get around this? Thanks, Paul
This comment was minimized by the moderator on the site
Hey,

Try this:

Sub LinkCheckBoxes()
Dim chk As CheckBox
Dim lCol As Long
lCol = 2 'number of columns to the right for link

For Each chk In ActiveSheet.CheckBoxes
With chk
.LinkedCell = _
.TopLeftCell.Offset(0, lCol).Address
End With
Next chk

End Sub



If you have for example, checkboxes in D,E,F change "Icol" to 1, so it links to G,H and I, respectively.
This comment was minimized by the moderator on the site
Hi, I have the same issue but did not work for me, can you help please.Thanks
This comment was minimized by the moderator on the site
thank you very much
This comment was minimized by the moderator on the site
Can you help me out with this same problem?
This comment was minimized by the moderator on the site
Can I do this and program the boxes to say something other than true and false?
This comment was minimized by the moderator on the site
Hi, In your VBA code: link checkboxes to multiple cells at once, the code is set up to link the cell below it. How is the code if I want to link the cell to the left of the first one? Thanks!
This comment was minimized by the moderator on the site
i have more than 40000 cell which have checkbox. when i use this code, it takes more than 5 second to process, i define different macros for different cells but i have still the problem, what can i do?
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations