具有多列、列名 "sku" 和列号“17”的组合框
ComboBox with multiple columns, Column Name "sku" and Column Number "17"
我正在尝试创建一个两列组合框。
计划是在 ComboBox 中 select "sku" 并将“17”(从列 Q1 派生)传递给排序过程。
A 行包含列名,在本例中 "sku" 位于单元格 "Q1" 中。
我有 10 个工作表要用不同的列名和总列数对所有工作表进行排序。所以我不能硬编码任何东西。我需要 select "sku" 并将“17”传递给排序子例程。
我相信我正在正确加载 ComboBox。我有 187 列,计数器我一直数到 187,直到出现类型不匹配。
我看这个太久了,只见树木不见森林:-)
A 行的样本数据
upc post_title post_name ID post_excerpt post_content post_status menu_order post_date post_parent post_author comment_status 库存可下载虚拟可见性 sku stock_status
这是我现在的代码:
Private Sub UserForm_Initialize()
With Me
.StartUpPosition = 0
.Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
.Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
.Show
End With
Dim i As Integer
Dim Cell As Variant
Dim ws As Worksheet
Dim lngLastColumn As Long
Me.ComboBox2.Clear
Me.ComboBox2.ColumnCount = 2
lngLastColumn = Worksheets("BirdFeet").Range("A1").CurrentRegion.Columns.Count
For Each Cell In Range("A1:" & Split(Cells(, lngLastColumn).Address, "$")(1) & lngLastColumn)
With Me.ComboBox2
For i = 0 To lngLastColumn - 1
.AddItem Cell
.List(.ListCount - 1, 1) = Cell.Column
Next i
End With
Next Cell
End Sub
好吧,我累了,所以当我累了我就回到最基本的。我从头开始,在最后半小时里比我一整天走得更远。
这就是我现在加载二维数组的方式。它正在加载列名和具有关联列号的第二列。该数字基于读取周期的循环次数。
这是我现在的代码。
Private Sub UserForm_Initialize()
With Me
.StartUpPosition = 0
.Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
.Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
.Show
End With
Dim intColumns As Integer, i As Integer
intColumns = WorksheetFunction.CountA(Worksheets("BirdFeet").Rows(1))
Dim ColumnNames() As String
ReDim ColumnNames(1, intColumns)
For i = 0 To intColumns - 1
ColumnNames(0, i) = Cells(1, i + 1).value
ColumnNames(1, i) = i + 1
Next i
End Sub
我正在尝试创建一个两列组合框。
计划是在 ComboBox 中 select "sku" 并将“17”(从列 Q1 派生)传递给排序过程。
A 行包含列名,在本例中 "sku" 位于单元格 "Q1" 中。
我有 10 个工作表要用不同的列名和总列数对所有工作表进行排序。所以我不能硬编码任何东西。我需要 select "sku" 并将“17”传递给排序子例程。
我相信我正在正确加载 ComboBox。我有 187 列,计数器我一直数到 187,直到出现类型不匹配。
我看这个太久了,只见树木不见森林:-)
A 行的样本数据
upc post_title post_name ID post_excerpt post_content post_status menu_order post_date post_parent post_author comment_status 库存可下载虚拟可见性 sku stock_status
这是我现在的代码:
Private Sub UserForm_Initialize()
With Me
.StartUpPosition = 0
.Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
.Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
.Show
End With
Dim i As Integer
Dim Cell As Variant
Dim ws As Worksheet
Dim lngLastColumn As Long
Me.ComboBox2.Clear
Me.ComboBox2.ColumnCount = 2
lngLastColumn = Worksheets("BirdFeet").Range("A1").CurrentRegion.Columns.Count
For Each Cell In Range("A1:" & Split(Cells(, lngLastColumn).Address, "$")(1) & lngLastColumn)
With Me.ComboBox2
For i = 0 To lngLastColumn - 1
.AddItem Cell
.List(.ListCount - 1, 1) = Cell.Column
Next i
End With
Next Cell
End Sub
好吧,我累了,所以当我累了我就回到最基本的。我从头开始,在最后半小时里比我一整天走得更远。
这就是我现在加载二维数组的方式。它正在加载列名和具有关联列号的第二列。该数字基于读取周期的循环次数。
这是我现在的代码。
Private Sub UserForm_Initialize()
With Me
.StartUpPosition = 0
.Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
.Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
.Show
End With
Dim intColumns As Integer, i As Integer
intColumns = WorksheetFunction.CountA(Worksheets("BirdFeet").Rows(1))
Dim ColumnNames() As String
ReDim ColumnNames(1, intColumns)
For i = 0 To intColumns - 1
ColumnNames(0, i) = Cells(1, i + 1).value
ColumnNames(1, i) = i + 1
Next i
End Sub