我有以下代码:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Selection.Count = 1 Then
If Not Intersect(Target, Range("A:A")) Is Nothing Then
Dim cb As Object
Dim combineRange As Range
Dim boolStr As String
Dim floatStr As String
Dim booleanRange As Range
Dim floatRange As Range
Dim bRow As Integer
bRow = Worksheets("DEF_BOOLEAN").Cells(Rows.Count, 1).End(xlUp).Row
Dim fRow As Integer
fRow = Worksheets("DEF_FLOAT").Cells(Rows.Count, 1).End(xlUp).Row
boolStr = "A2:A" & bRow
floatStr = "A2:A" & fRow
Set booleanRange = Worksheets("DEF_BOOLEAN").Range(boolStr)
Set floatRange = Worksheets("DEF_FLOAT").Range(floatStr)
Set cb = Worksheets("FT_CASE_xx").OLEObjects.Add(ClassType:="Forms.ComboBox.1", Link:=False, DisplayAsIcon:=False, Left:=Target.Left, Top:=Target.Top, Width:=Target.Width, Height:=Target.Height).Object
For Each cell In booleanRange
cb.AddItem cell.value
Next cell
For Each cell In floatRange
cb.AddItem cell.value
Next cell
End If
End If
End Sub
,每当我在“ A”列中按一个单元格时,它就会添加一个ActiveX组合框。 很好问题是我希望下面的单元格(被组合框“覆盖”的单元格)获得在组合框中选择的值。
这就是为什么我想使用linkedCell属性。不幸的是,以下几行不起作用:
cb.LinkedCell = Target
或
cb.LinkedCell = Target.address
应该如何设置以达到结果?
答案 0 :(得分:1)
稍作更改对我有用:将Dim cb As Object
更改为Dim cb as ComboBox
。
然后使用cb.LinkedCell = Target.Address
。