我为表单控件复选框.LinkedCell = Worksheets("sheet1").Range("D" & myCell.Row & "").Value
设计了一个链接单元格引用,遗憾的是它不会链接到指定的单元格。虽然,标题参考确实有效。我把整个宏放在下面:
Sub test()
Dim myBox As CheckBox
Dim myCell As Range
Dim cellRange As String
With ActiveSheet
For Each myCell In .Range("B10:B12").Cells
With myCell
Set myBox = .Parent.CheckBoxes.Add(Top:=.Top, Width:=.Width, Left:=.Left, Height:=.Height)
With myBox
.LinkedCell = Worksheets("sheet1").Range("D" & myCell.Row & "").Value
.Caption = Worksheets("sheet1").Range("B" & myCell.Row & "").Value
.Name = "checkbox_" & myCell.Address(0, 0)
End With
.NumberFormat = ";;;"
End With
Next myCell
End With
End Sub
我也试图以这种方式引用单元格:.Range("sheet1!B" & myCell.Row).Value
。这种方法完全失败了。
答案 0 :(得分:0)
您需要.Address
而不是.Value
。试试这个
.LinkedCell = Worksheets("sheet1").Range("D" & myCell.Row).Address
或
.LinkedCell = ActiveSheet.Range("D" & myCell.Row).Address
在指定行之后,您也不需要""
。因此"B" & myCell.Row & ""
可以写成"B" & myCell.Row