ListBox の BoundColumnプロパティにセットした列は、ListBox1.Value で、
ListBox の TextColumnプロパティにセットした列は、ListBox1.Text で、
値を取得できますが、ListBoxに、もっと多くの列がある場合、各列のデータをどう取得する?

Listプロパティの、(行,列) の2次元配列でデータを取得できます。
me.ListBox1.List(row, Column)


VBAProject --> フォーム --> UserFormXX

Private Sub CommandButton1_Click()
    Dim lngInpRow As Long
    Dim lngListIndex As Long

    lngListIndex = Me.ListBox1.ListIndex
    
    If lngListIndex = -1 Then Exit Sub

    lngInpRow = 10
    
    Cells(lngInpRow, "F").Value = Me.ListBox1.List(lngListIndex, 0)
    Cells(lngInpRow, "G").Value = Me.ListBox1.List(lngListIndex, 1)
    Cells(lngInpRow, "H").Value = Me.ListBox1.List(lngListIndex, 2)
    Cells(lngInpRow, "I").Value = Me.ListBox1.List(lngListIndex, 3)
    Cells(lngInpRow, "J").Value = Me.ListBox1.List(lngListIndex, 4)
    Cells(lngInpRow, "K").Value = Me.ListBox1.List(lngListIndex, 5)
    Cells(lngInpRow, "L").Value = Me.ListBox1.List(lngListIndex, 6)
    Cells(lngInpRow, "M").Value = Me.ListBox1.List(lngListIndex, 7)
    Cells(lngInpRow, "O").Value = Me.ListBox1.List(lngListIndex, 9)
    Cells(lngInpRow, "P").Value = Me.ListBox1.List(lngListIndex, 10)
    
End Sub


 ↓ facebook のフォローで応援してください。お願いします。



Microsoft Office ブログランキングへ