|
- Sub qs()
- Application.ScreenUpdating = False
- Dim rng As Range, r As Range
- Set rng = Sheet3.Range("a2:r16")
- For Each r In rng
- If r.Value = True Then
- ' MsgBox r.Offset(0, 1).Value
- r.Offset(0, 1).Interior.Color = 65535
- Else
- r.Offset(0, 1).Interior.Pattern = xlNone
- End If
- Next
- Application.ScreenUpdating = True
- End Sub
- Sub InsertCheckboxesAndHideText()
- Dim ws As Worksheet
- Dim col As Long
- Dim row As Long
- Dim cb As Object
- Dim colArray As Variant
- Dim i As Long
-
- ' 设置要操作的工作表
- Set ws = ThisWorkbook.Sheets("初始赋值")
-
- ' 指定需要插入复选框的列:A, C, E, G, ..., Q(隔列)
- colArray = Array(1, 3, 5, 7, 9, 11, 13, 15, 17) ' 这些是列号
-
- ' 遍历指定列并在第2行到第16行中插入复选框
- For i = LBound(colArray) To UBound(colArray)
- col = colArray(i)
-
- ' 在每列的2到16行中插入复选框
- For row = 2 To 17
- m = m + 1
- ' 插入复选框
- Set cb = ws.CheckBoxes.Add(ws.Cells(row, col).Left, ws.Cells(row, col).Top, ws.Cells(row, col).Width, ws.Cells(row, col).Height)
- cb.Caption = "" ' 去掉复选框的标题
- cb.linkedCell = ws.Cells(row, col).Address ' 将复选框与所在单元格链接
- cb.Display3DShading = True ' 设置复选框为三维阴影效果
- cb.Name = "cx" & m
-
- If m Mod 16 = 0 Then
- cb.OnAction = "sq" '绑定的宏
- Else
- cb.OnAction = "qs" '绑定的宏
- End If
-
- ' 设置单元格字体颜色为与背景相同,使TRUE或FALSE不可见
- ws.Cells(row, col).Font.Color = ws.Cells(row, col).Interior.Color ' 字体颜色设置为与背景颜色相同
- Next row
- Next i
- End Sub
- Sub sq()
- For c = 1 To 17 Step 2
- If Sheet3.Cells(17, c) = True Then
- Sheet3.Cells(17, c).Offset(-15, 0).Resize(15, 1) = True
- Call qs
- Else
- Sheet3.Cells(17, c).Offset(-15, 0).Resize(15, 1) = False
- Call qs
- End If
- Next c
- End Sub
- Sub 删除所有复选框()
- Dim ws As Worksheet
- Dim cb As CheckBox
-
- ' 设置要操作的工作表
- Set ws = ThisWorkbook.Sheets("初始赋值")
-
- ' 遍历并删除工作表中的所有复选框
- For Each cb In ws.CheckBoxes
- cb.Delete
- Next cb
- End Sub
复制代码 |
|