如何设置 ActiveX 组合框链接单元格属性



我有以下代码:

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

应该如何设置才能实现结果?

一个小小的变化对我有用:将Dim cb As Object更改为Dim cb as ComboBox

然后使用 cb.LinkedCell = Target.Address .

最新更新