title: VBA Filing Arrays and creating columns
body: <p>I need to write a sub that captures the existing lists in two arrays and then create two new arrays of customer names and amounts spent for customers who spent at least $500. After these new arrays have been filled, I have to write them in columns D and E.</p>
  
  <p>So say column 1 is from A3:A50 and this has the customer's names
  and column 2 is from C3:50 with the sales price that the customer purchase.</p>
  
  <p>I am having trouble writing the part of the code that sorts through the arrays and decides if the sales price is greater than $500. Can someone point me where its going wrong?</p>
  
  <p>This is what I have so far but it does not work:</p>
  
  <pre><code>Sub ProductSales()
  ' These are inputs: the number of customers, the customer's name,
  ' and the dollar amount of each sale.
  Dim nCustomers As Integer
  Dim namesData() As String
  Dim dollarsData() As Integer
  
  ' The following are outputs: the customer name found over 500, and the number
  'of customer over 500
  Dim customerFound() As String
  Dim customerCount() As Integer
  
  ' Variables used in finding if sale is over 500
  Dim isOver As Boolean
  Dim nFound As Integer
  
  ' Counters.
  Dim i As Integer
  Dim j As Integer
  
  ' Clear any old results in columns E to G.
  With wsData.Range("E2")
      Range(.Offset(1, 0), .Offset(0, 2).End(xlDown)).ClearContents
  End With
  
  ' Find number of customers in the data set, redimension the namesdata and
  ' dollarsData arrays, and fill them with the data in columns A and C.
  With wsData.Range("A2")
      nCustomers = Range(.Offset(1, 0), .End(xlDown)).Rows.Count
      ReDim namesData(1 To nCustomers)
      ReDim dollarsData(1 To nCustomers)
      For i = 1 To nCustomers
          namesData(i) = .Offset(i, 0).Value
          dollarsData(i) = .Offset(i, 2).Value
      Next
  End With
  
  ' Initialize the number of names found to 0.
  nFound = 0
  
  ' Loop through all sales.
  For i = 1 To nCustomers
  
      ' Set the Boolean isOver to False, and change it to True only
      ' if the sale is over 500
      isOver = False
      If nFound &gt; 0 Then
          ' Loop through all customer names already found and add to new list
          ' and exit loop
          For j = 1 To nFound
              If dollarsData(i) &gt; 500 Then
                  isOver = True
                  customerCount(j) = customerCount(j) + 1
                  Exit For
              End If
          Next
      End If
  
      If isOver Then
          ' The current product code is a new one, so update the list of
          ' codes found so far, and initialize the transactionsCount and dollarsTotal
          ' values for this new product.
          nFound = nFound + 1
          ReDim Preserve customerFound(1 To nFound)
          ReDim Preserve customerCount(1 To nFound)
          customerCount(nFound) = namesData(i)
          customerCount(nFound) = 1
  
      End If
  Next
  
  ' Place the results in columns E to G.
  For j = 1 To nFound
      With wsData.Range("E2")
          .Offset(j, 0).Value = customerFound(j)
          .Offset(j, 1).Value = customerCount(j)
  
      End With
  Next
  </code></pre>
  
  <p>End Sub</p>