表单控件checkboxlinkedcell参考失败
我devise了一个表单控件checkbox的链接单元格引用.LinkedCell = Worksheets("sheet1").Range("D" & myCell.Row & "").Value
,不幸的是不会链接到指定的单元格。 虽然,标题引用确实有效。 我把整个macros放在下面:
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
。 此方法完全失败。
你需要.Address
而不是.Value
。 尝试这个
.LinkedCell = Worksheets("sheet1").Range("D" & myCell.Row).Address
要么
.LinkedCell = ActiveSheet.Range("D" & myCell.Row).Address
在指定行之后,您也不需要""
。 所以"B" & myCell.Row & ""
可以写成"B" & myCell.Row