I have a sub that fills an array with a list of user defined values from a fixed range in my spreadsheet. I want to call this sub from another, and utilize the values in the array to drive a For Each loop.
When I call the sub getInvoiceList I can see that it does fill the array invoiceList with the user's values. But they don't pass back into the sub I call from.
Public Sub columnLoop()
Dim i As Long, j As Long
getInvoiceList
Stop 'to view array values
Sheets("Calculator").Columns(10).Font.Color = vbBlack
For i = 0 To UBound(invoiceList)
'Loops through column for specific value(as declared)
'Recolors text when current cell value = specific value
For j = 3 To Range("NumFilledRows").Value
If Sheets("Calculator").Cells(j, 10).Value = invoiceList(i) Then
Sheets("Calculator").Cells(j, 10).Font.Color = vbRed
End If
Next j
Next i
End Sub
'Fill array from fixed range
Public Sub getInvoiceList()
Dim invoiceList() As Variant
invoiceList = Sheet2.Range("C4:C14")
Stop 'allows review of array.
End Sub
When I call the sub 'getInvoiceList' I can see that it does fill the array invoiceList with the user's values. But they don't pass back into the sub I call from.
Run-time error '13': Type Mismatch
Debug takes me to the For i = 0 to UBound line.
Locals window shows invoiceList but has value = empty both on Stop line and after clicking debug.
Dim invoiceList() As Variantoutside of the Sub so it's accessible by everything in the module.