Excel Vba 批量添加复选框 如何判断复选框已被选中
展开全部
如一个Excel点名簿要批量添加复选框,已到的打勾,没到的不打勾
可以先用录制宏功能,学习一下vba代码,调试的时候多用msgbox函数和 msdn的官方帮助 google
用EXCEL VBA实现
------------------------------------------------------------------------------------
Sub Macro4()'' Macro1 Macro
For i = 1 To 2
ActiveSheet.CheckBoxes.Add(Cells(i, 1).Left, Cells(i, 1).Top, 24, 16.5).Select '在cells(i,1)处添加复选框
ActiveSheet.Shapes("Check Box " + Str(i)).Select
Selection.Characters.Text = "" '把复选框右边系统自带的注释清空
With Selection
.Value = xlOff
.LinkedCell = "$B$" + Trim(Str(i)) '如果i=1的话,则在B1单元格处显示A1单元格中的复选框是否被选中
' MsgBox """" + "$D$" + Trim(Str(i)) + """"
' MsgBox """" + "$D$1" + """"
.Display3DShading = FalseEnd WithNext iRange("E5").SelectEnd Sub-------------------------------------------------------------------------------------------------------------------------
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
' [a1] = "单元格 "
' [b1] = "第一行顶端到该单元格顶端的距离: "
' [c1] = "从A列左边界至该单元格左边界的距离: "
[a2] = Target.Address ’单元格在第几行第几列
[b2] = Target.Top ‘单元格离上边界的距离
[c2] = Target.Left ’单元格离左边界的距离
[d2] = Target.Height ’单元格行高
[e2] = Target.Width ‘单元格列宽
字符串转数值函数 val
数值转字符串函数 str
添加单引号 四个引号最后得出的是单引号 MsgBox """" + "$D$" + Trim(Str(i)) + """" 去掉空格的函数 trim
可以先用录制宏功能,学习一下vba代码,调试的时候多用msgbox函数和 msdn的官方帮助 google
用EXCEL VBA实现
------------------------------------------------------------------------------------
Sub Macro4()'' Macro1 Macro
For i = 1 To 2
ActiveSheet.CheckBoxes.Add(Cells(i, 1).Left, Cells(i, 1).Top, 24, 16.5).Select '在cells(i,1)处添加复选框
ActiveSheet.Shapes("Check Box " + Str(i)).Select
Selection.Characters.Text = "" '把复选框右边系统自带的注释清空
With Selection
.Value = xlOff
.LinkedCell = "$B$" + Trim(Str(i)) '如果i=1的话,则在B1单元格处显示A1单元格中的复选框是否被选中
' MsgBox """" + "$D$" + Trim(Str(i)) + """"
' MsgBox """" + "$D$1" + """"
.Display3DShading = FalseEnd WithNext iRange("E5").SelectEnd Sub-------------------------------------------------------------------------------------------------------------------------
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
' [a1] = "单元格 "
' [b1] = "第一行顶端到该单元格顶端的距离: "
' [c1] = "从A列左边界至该单元格左边界的距离: "
[a2] = Target.Address ’单元格在第几行第几列
[b2] = Target.Top ‘单元格离上边界的距离
[c2] = Target.Left ’单元格离左边界的距离
[d2] = Target.Height ’单元格行高
[e2] = Target.Width ‘单元格列宽
字符串转数值函数 val
数值转字符串函数 str
添加单引号 四个引号最后得出的是单引号 MsgBox """" + "$D$" + Trim(Str(i)) + """" 去掉空格的函数 trim
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询