I am having trouble with looping through my already defined array to find values that are over 500. It is telling me that my subscript is out of range.
This is what I have so far. Can someone help me to fix the second part, so it will properly loop through the already established arrays.
Sub hishSale()
Dim customers() As String
Dim sale() As String
Dim hiCustomer() As String
Dim hiSale() As String
Dim nCustomers As Integer
Dim i As Integer
Dim isOver As Integer
'capture the number of customers and sales and put them in two seperate arrays
With wsData.Range("A3")
nCustomers = Range(.Offset(1, 0), .End(xlDown)).Rows.Count
ReDim customers(nCustomers)
ReDim sale(nCustomers)
For i = 1 To nCustomers
customers(i) = .Offset(i, 0).Value
sale(i) = .Offset(i, 1).Value
Next
End With
'Loop through arrays to find sales over $500
With Range("A3")
isOver = 0
For i = 1 To nCustomers
If .Offset(i, 1).Value > 500 Then
isOver = isOver + 1
hiCustomer(isOver) = .Offset(i, 0).Value
hiSale(isOver) = .Offset(isOver, 1).Value
End If
Next
End With
'return results in columns D and E
With Range("D3")
For i = 1 To nCustomers
.Offset(i, 0) = hiCustomer(isOver)
.Offset(i, 1) = hiSale(isOver)
Next
End With
End Sub
for lbound(customers()) to ubound(customers())ito index intohiCustomerandhiSale? You're usingisOver, the value of which is fixed at this pointWith Range("D3") For i = 1 To nCustomers .Offset(i, 0) = hiCustomer(isOver) .Offset(i, 1) = hiSale(isOver) Next End With.Offset(i, 0) = hiCustomer(isOver)--- is giving me an error