Anyone have any idea why i am getting a subscript out of range error at the IF statement. I am just learning arrays so i can only assume it has to do with that.
Dim CARMA2 As Worksheet
Dim Assignments As Worksheet
Sub data2()
Dim arr() As Variant
Dim CAR() As Variant
arr = Array(Worksheets("Assignments").UsedRange)
CAR = Array(Worksheets("CARMA2").UsedRange)
Dim i As Variant
For x = LBound(CAR, 1) To UBound(CAR, 1)
For i = LBound(arr, 1) To UBound(arr, 1)
If arr(i, 5) = CAR(x, 1) And arr(i, 7) = """" Then
arr(i, 7) = CAR(x, 3)
End If
Next i
Next x
End Sub
7inarr(i, 7)as an example) is probably out of bounds/doesn't exist. What are the sizes of these two arrays when your code hits theifstatement? It may help to note, since you are new to arrays, that arrays almost always start at index 0, not index 1. So perhaps you meantIf arr(i, 4) = CAR(x, 0) And arr(i, 6) = """" Then arr(i, 6) = CAR(x, 2)?Array()you are assigning a single range object to arrayarr, the same with arrayCAR. So you have index boundaries of0 To 0referencing a single object in a zero-based 1-dimensional array. - Therefore I suspect you intended to create a (1-based!) 2-dim datafield array which can be done e.g. byarr = ThisWorkbook.Worksheets("Assignments").UsedRangeinstead; now you are able to reference values indexed e.g. byarr(i, 5)andarr(i, 7)etc. @JoshHudsonarr = Sheet1.UsedRangewithout adding the.Valueproperty explicitly. Meanwhile Dick has already summarized some points worth knowing in his accepted answer concerning especially the differences betweenDim arr As VariantandDim arr() As Variantand in his comment about the special behaviour of the.Valueor.Value2prop in connection withUsedRange.