Excel VBA:访问选定列表框行中的单个字段

我试图访问选定/突出显示的列表框"lstData"行中的单个单元格,以便我可以在其他地方引用它们的值。

当我为Me.lstData.SelectedItem设置一个手表时,我Expression not defined in context 。 与Me.lstData.SelectedIndexMe.lstData.Rows(1) 。 对我来说唯一的作用是Me.lstData.Value ,但它只返回最左边的单元格。 当我尝试将其插入=OFFSET函数

 =Offset(Me.lstData.Value, ,1,1) 

要立即访问单元格的右侧,我得到的Expression not defined in context再次Expression not defined in context

我怎样才能引用其他选定的单元格?

我不认为你可以使用ListBox窗体控件上的Offset 。 在多列ListBox引用“单元格”的方式是通过索引List属性。

在这里, i返回所选项目的1代表列表框的第二列(基础0):

 Option Explicit Private Sub CommandButton1_Click() Dim i As Long With Me.ListBox1 i = .ListIndex MsgBox .List(i, 1) End With End Sub Private Sub UserForm_Initialize() With Me.ListBox1 .AddItem "A" .List(0, 1) = "Alpha" .AddItem "B" .List(1, 1) = "Beta" End With End Sub 

在这里输入图像说明