Hi
I've managed to come up with this code:
Its using the array to analyse some data and set a value (typically using the number 20) based on that data.
There's quite a few different rules analysing different things that ultimately do the same thing.
I would like to simplify this code and perhaps pick up some of the rules from cells on a worksheet (in another array?). But I don't know where to start.
Thanks
I've managed to come up with this code:
Code:
Dim v, i As Long
v = Range("D2:Q" & Range("D" & Rows.Count).End(xlUp).Row).Value
'
For i = 1 To UBound(v)
'N Is 20
If Left(v(i, 3), 1) = "N" Then
v(i, 2) = "20"
End If
'0 = 20
If v(i, 4) = "0" Then
v(i, 2) = "20"
End If
' M-RT = Op20
If (Left(v(i, 9), 4) = "M-RT") Then
v(i, 2) = "20"
End If
' M-RT = Op20
If (Left(v(i, 11), 4) = "M-RT") Then
v(i, 2) = "20"
End If
' M-RT = Op20
If (Left(v(i, 13), 4) = "M-RT") Then
v(i, 2) = "20"
End If
' (Area5) = Op20
If (Left(v(i, 10), 7) = "(AREA5)") Then
v(i, 2) = "20"
End If
If (Left(v(i, 12), 7) = "(AREA5)") Then
v(i, 2) = "20"
End If
If (Left(v(i, 14), 7) = "(AREA5)") Then
v(i, 2) = "20"
End If
' (Area 7) = Op20
If (Left(v(i, 10), 7) = "(AREA7)") Then
v(i, 2) = "20"
End If
If (Left(v(i, 12), 7) = "(AREA7)") Then
v(i, 2) = "20"
End If
If (Left(v(i, 14), 7) = "(AREA7)") Then
v(i, 2) = "20"
End If
'T not added
If Left(v(i, 3), 1) = "T" Then
v(i, 2) = "T"
End If
'LA not added
If Left(v(i, 3), 2) = "LA" Then
v(i, 2) = "LA"
End If
'C not added
If Left(v(i, 3), 1) = "C" Then
v(i, 2) = "C"
End If
Next i
Range("D2:E2").Resize(UBound(v)).Value = v
Its using the array to analyse some data and set a value (typically using the number 20) based on that data.
There's quite a few different rules analysing different things that ultimately do the same thing.
I would like to simplify this code and perhaps pick up some of the rules from cells on a worksheet (in another array?). But I don't know where to start.
Thanks