Hi,
I have a row of data that I want to use in a ListBox.
Lets say Row1 Column 1 to Column14 - "A1:N1"
I have the Range three ways:
A horizontal named range "Choices"
A horizontal array of the Values of the range.
A vertical array of the Values of the range.
I am trying to populate a listbox on a form so that I can select a value which will then select the cell of that value so that I can run a macro on the column.
I am trying to avoid the "clutter" of having an extra column on the worksheet with the transposed values.
Dim These_Cols as Long
These_Cols = Cells(1, Columns.Count).End(xlToLeft).Column
Range("A1").Select
Set Choices = Range(Selection, Selection.End(xlToRight))
ThisWorkbook.Names.Add Name:="Choices", RefersTo:=Choices
Dim Choices1() As Variant
ReDim Choices1(These_Cols) As Variant
Dim j As Long
For j = 2 To These_Cols
Choices1(j - 2) = Cells(2, j).Value
Next j
ThisWorkbook.Names.Add Name:="Choices1", RefersTo:=Choices1
Dim Choices2() As Variant
ReDim Choices2(These_Cols, 0) As Variant
Dim j As Long
For j = 2 To These_Cols
Choices2(j - 2, 0) = Cells(2, j).Value
Next j
ThisWorkbook.Names.Add Name:="Choices2", RefersTo:=Choices2
For the user form:
Private Sub UserForm_Initialize()
Set rnData = ActiveSheet.Range("Choices2")
vaData = rnData.Value
With Me.ListBox1
.Clear
.List = vaData
.ListIndex = -1
End With
End Sub
I have a row of data that I want to use in a ListBox.
Lets say Row1 Column 1 to Column14 - "A1:N1"
I have the Range three ways:
A horizontal named range "Choices"
A horizontal array of the Values of the range.
A vertical array of the Values of the range.
I am trying to populate a listbox on a form so that I can select a value which will then select the cell of that value so that I can run a macro on the column.
I am trying to avoid the "clutter" of having an extra column on the worksheet with the transposed values.
Dim These_Cols as Long
These_Cols = Cells(1, Columns.Count).End(xlToLeft).Column
Range("A1").Select
Set Choices = Range(Selection, Selection.End(xlToRight))
ThisWorkbook.Names.Add Name:="Choices", RefersTo:=Choices
Dim Choices1() As Variant
ReDim Choices1(These_Cols) As Variant
Dim j As Long
For j = 2 To These_Cols
Choices1(j - 2) = Cells(2, j).Value
Next j
ThisWorkbook.Names.Add Name:="Choices1", RefersTo:=Choices1
Dim Choices2() As Variant
ReDim Choices2(These_Cols, 0) As Variant
Dim j As Long
For j = 2 To These_Cols
Choices2(j - 2, 0) = Cells(2, j).Value
Next j
ThisWorkbook.Names.Add Name:="Choices2", RefersTo:=Choices2
For the user form:
Private Sub UserForm_Initialize()
Set rnData = ActiveSheet.Range("Choices2")
vaData = rnData.Value
With Me.ListBox1
.Clear
.List = vaData
.ListIndex = -1
End With
End Sub