Hi All,
I'm in need of a bit of assistance, I'm sure it's a very simple tweak but I'm struggling to get my VBA code to do what I want...
I'm trying to see if a number is present on another sheet, and if so colour it in. So I'm trying to save two arrays, one a 'stocklist' (built) and another an 'allocated' (assigned) list, and cross check them.
So far I've got:
Private Sub Workbook_Open()
Dim Assigned As Variant, Built As Variant, i As Long, j As Long
ActiveWorkbook.Sheets("Module Assignment").Select
Assigned = Range(Range("B2"), Range("B2").End(xlDown)).Value
ActiveWorkbook.Sheets("Build Sheet").Select
Built = Selection.Range(Range("C2"), Range("C2").End(xlDown)).Value
For i = 1 To UBound(Assigned)
For j = 1 To UBound(Built)
If Assigned(i).Value = Built(j).Value Then
cells(i + 1, 3).Interior.ColorIndex = 3
End If
Next j
Next i
End Sub
I'm getting 'Run-time error '9': Subscript out of range' so I assume it's a problem with trying to call a single value from each array to compare. However, after scrolling through various forum posts I can't seem to find a solution.
Any input would be really appreciated!
Sam
I'm in need of a bit of assistance, I'm sure it's a very simple tweak but I'm struggling to get my VBA code to do what I want...
I'm trying to see if a number is present on another sheet, and if so colour it in. So I'm trying to save two arrays, one a 'stocklist' (built) and another an 'allocated' (assigned) list, and cross check them.
So far I've got:
Private Sub Workbook_Open()
Dim Assigned As Variant, Built As Variant, i As Long, j As Long
ActiveWorkbook.Sheets("Module Assignment").Select
Assigned = Range(Range("B2"), Range("B2").End(xlDown)).Value
ActiveWorkbook.Sheets("Build Sheet").Select
Built = Selection.Range(Range("C2"), Range("C2").End(xlDown)).Value
For i = 1 To UBound(Assigned)
For j = 1 To UBound(Built)
If Assigned(i).Value = Built(j).Value Then
cells(i + 1, 3).Interior.ColorIndex = 3
End If
Next j
Next i
End Sub
I'm getting 'Run-time error '9': Subscript out of range' so I assume it's a problem with trying to call a single value from each array to compare. However, after scrolling through various forum posts I can't seem to find a solution.
Any input would be really appreciated!
Sam