我有一个名为“调查”的工作表。我正在尝试将复选框附加到 A 列中答案旁边的所有单元格,并且由于某种原因,我收到“需要对象”错误。开头附近的 4 行以“Set rng =”开头,被突出显示。
我对 VBA 很陌生,所以我不确定这是否只是一个我没有看到的简单语法问题。我已经尝试搜索正确的格式,但无济于事。任何人都可以帮忙吗?这是我得到的代码:
Sub AddCheckBox()
Dim rng As Range
Dim rcell As Range
Set rng = Survey.Range("A7:A10,A13:A17,A21:A25,A28:A33" _
& "A36:A43, A48,A51:A56,A60:A66,A69:A73,A76:A80" _
& "A83:A87, A90:A94, A97:A102, A105:A113, A116:A122, A125:A131" _
& "A134:A141,A145:A149, A152:A158, A161:A165")
DelCheckBox
For Each rcell In rng
With ActiveSheet.CheckBoxes.Add(rcell.Left, _
rcell.Top, rcell.Width, rcell.Height)
.LinkedCell = rcell.Offset(, 0).Address(External:=True)
.Interior.ColorIndex = 14 'or xlNone or xlAutomatic
.Caption = ""
.Border.Weight = xlThin
End With
Next
With Range("A7:A10,A13:A17,A21:A25,A28:A33" _
& "A36:A43, A48,A51:A56,A60:A66,A69:A73,A76:A80" _
& "A83:A87, A90:A94, A97:A102, A105:A113, A116:A122, A125:A131" _
& "A134:A141,A145:A149, A152:A158, A161:A165")
.Rows.RowHeight = 15
End With
End Sub
Sub DelCheckBox()
For Each cell In Range("A1:A166")
Worksheets("Survey").CheckBoxes.Delete
Next
End Sub