我的列表框在表单上。当用户选择列表项时,它们将存储在列中。稍后当单击 m 编辑按钮时,我想读取这些值并将它们添加到表单上的选定列表 (Listbox_selectedCategories) 中并将它们从另一个列表框 (Listbox_categories) 中删除 VBA 编辑器抛出的错误是错误 381无法获取列表属性。无效的属性数组索引。我已经检查了按预期迭代的即时窗口中的 x 和 index 的值。我也尝试过没有 Cstr 函数,同样的错误。编译器将 if 语句突出显示为错误点。我确定这是一些基本的误解,我将不胜感激任何帮助或指导。谢谢。
Public Sub dataLoad()
Dim x As Integer
x = 0
NewQueryForm.targetingDescription.value = ActiveCell.Offset(1, 0).value
NewQueryForm.booleanDescription.value = ActiveCell.Offset(1, 1).value
NewQueryForm.startDate.value = ActiveCell.Offset(1, 3).value
NewQueryForm.endDate.value = ActiveCell.Offset(1, 4).value
NewQueryForm.dfpCount.value = ActiveCell.Offset(1, 5).value
NewQueryForm.Text_300Rates = ActiveCell.Offset(1, 8).value
NewQueryForm.Text_160Rates = ActiveCell.Offset(2, 8).value
NewQueryForm.Text_728Rates = ActiveCell.Offset(3, 8).value
NewQueryForm.Text_PollRates = ActiveCell.Offset(4, 8).value
NewQueryForm.Text_CMRates = ActiveCell.Offset(5, 8).value
NewQueryForm.Text_ExCMRates = ActiveCell.Offset(6, 8).value
Call NewQueryForm_Initialize
Sheets("CAT").Activate
Range("A1").Activate
ActiveCell.Offset(0, loopCount).Activate
While ActiveCell.Offset(1, 0).value <> ""
x = x + 1
Dim index As Integer
'Adding and removing items from list
NewQueryForm.ListBox_selectedCategories.AddItem ActiveCell.Offset(x - 1, 0).value
For index = 0 To NewQueryForm.ListBox_categories.ListCount - 1
If CStr(NewQueryForm.ListBox_categories.List(index)) = ActiveCell.Offset(x - 1, 0).value Then
NewQueryForm.ListBox_categories.RemoveItem (index)
End If
Next index
'Adding and Subtracting from global percent label variables
selectedCategoryLabel = selectedCategoryLabel + categoryPercent(ActiveCell.Offset(x - 1, 0).value)
categoryLabel = categoryLabel - categoryPercent(ActiveCell.Offset(x - 1, 0).value)
'Setting next cell down active
ActiveCell.Offset(1, 0).Activate
Wend
'updating labels
NewQueryForm.selectedPercent.Caption = CStr(Round(selectedCategoryLabel, 2)) & "%"
NewQueryForm.categoryPercent = CStr(Round(categoryLabel, 2)) & "%"
NewQueryForm.Show
End Sub