title: VBA EXCEL- Comparing listbox item to cell value (string)
body: <p>My list box is on a form. When a user selected list items they are stored in a column. Later when m edit button is clicked I would like to read in these values and add them onto a selected list (Listbox_selectedCategories) on the form and remove them from the other list box (Listbox_categories) The error that the VBA editor is throwing is error 381 could not get list property. Invalid property array index. I have checked both the value of x and index in the immediate window which are iterating as expected.I have also tried this without the Cstr function,same error. The compiler is highlighting the if statement as the point of error. Im sure this is some fundamental misunderstanding I would appreciate any help or direction. Thanks.</p>
  
  <pre><code> 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 &lt;&gt; ""
  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)) &amp; "%"
   NewQueryForm.categoryPercent = CStr(Round(categoryLabel, 2)) &amp; "%"
  
  
  
  
  
  NewQueryForm.Show
  End Sub
  </code></pre>