Excel 中的 ComboBox 到 return 值,而不是索引
ComboBox in Excel to return value, not index
我在 Sheet1!$A:$A 中有一系列重复的日期。我将这些作为独特的项目添加到带有 VBA 的组合框 (cb) 中。不幸的是,当我 select 一个项目(cb 中的日期)时,该项目的索引然后被 return 编辑到链接的单元格中。
有没有办法 return 日期而不是索引,或者将 cb 填充为项目对(日期,日期)?
A B C ____D_________
1 日期 val1 val2 |03/09/2015 |V |
2 03/08/2015 13 2.4 | __|_ |
3 2015 年 3 月 8 日 17 4.6
4 2015 年 3 月 8 日 11 2.5
5 2015 年 3 月 9 日 9 1.5
6 2015 年 3 月 10 日 4 3.2
7 2015 年 3 月 10 日 12 3.4
在上面的示例中,我的 cb 将在 D1(这是基础链接单元格)中 return 2,但我希望日期为 returned。有没有 "simple" 方法来完成这个?
这似乎不起作用:
With wsSheet2.Shapes("DatePick").ControlFormat
.RemoveAllItems
For Each vaItem In ncData
.AddItem vaItem, vaItem '<--- add an item pair
Next vaItem
End With
谢谢
您可以将格式控制选项中的 "cell link" 更改为 D1
,然后在单元格 D2
中输入:
=INDEX($A:$A,D1+1)
试试这个:
Sub TransferValue()
Dim dd As DropDown, linkedcell As String
linkedcell = Sheet1.Shapes("Drop Down 1").ControlFormat.linkedcell
Set dd = Sheet1.Shapes("Drop Down 1").OLEFormat.Object
Sheet1.Range(linkedcell) = dd.List(dd.Value)
End Sub
我假设你正在使用 Form Control
因为你有一个 LinkedCell
.
所以这基本上得到了 LinkedCell
地址,所以你可以使用相同的地址进行输出。
然后获取 ComboBox
或 DropDown Object
的值并将其传递给 LinkedCell
地址。您只需将此 Macro 分配给您的 ComboBox。 HTH.
我在 Sheet1!$A:$A 中有一系列重复的日期。我将这些作为独特的项目添加到带有 VBA 的组合框 (cb) 中。不幸的是,当我 select 一个项目(cb 中的日期)时,该项目的索引然后被 return 编辑到链接的单元格中。 有没有办法 return 日期而不是索引,或者将 cb 填充为项目对(日期,日期)?
A B C ____D_________ 1 日期 val1 val2 |03/09/2015 |V | 2 03/08/2015 13 2.4 |__|_| 3 2015 年 3 月 8 日 17 4.6 4 2015 年 3 月 8 日 11 2.5 5 2015 年 3 月 9 日 9 1.5 6 2015 年 3 月 10 日 4 3.2 7 2015 年 3 月 10 日 12 3.4
在上面的示例中,我的 cb 将在 D1(这是基础链接单元格)中 return 2,但我希望日期为 returned。有没有 "simple" 方法来完成这个?
这似乎不起作用:
With wsSheet2.Shapes("DatePick").ControlFormat
.RemoveAllItems
For Each vaItem In ncData
.AddItem vaItem, vaItem '<--- add an item pair
Next vaItem
End With
谢谢
您可以将格式控制选项中的 "cell link" 更改为 D1
,然后在单元格 D2
中输入:
=INDEX($A:$A,D1+1)
试试这个:
Sub TransferValue()
Dim dd As DropDown, linkedcell As String
linkedcell = Sheet1.Shapes("Drop Down 1").ControlFormat.linkedcell
Set dd = Sheet1.Shapes("Drop Down 1").OLEFormat.Object
Sheet1.Range(linkedcell) = dd.List(dd.Value)
End Sub
我假设你正在使用 Form Control
因为你有一个 LinkedCell
.
所以这基本上得到了 LinkedCell
地址,所以你可以使用相同的地址进行输出。
然后获取 ComboBox
或 DropDown Object
的值并将其传递给 LinkedCell
地址。您只需将此 Macro 分配给您的 ComboBox。 HTH.