possible to do a vlookup using colorindex?
Bob,
Thanks I ended up going the select case as I'm just lazy.
regards
David
Sub Dodgy()
Dim FindP As Double
Dim FindW As Double
Dim location As Range
Dim res As Double
Dim PGrowth, WGrowth As Double
Dim r, c, i As Integer
i = 0
For r = 0 To 3 ' 4 row
For c = 0 To 3 ' 4 columns
With Worksheets("trial")
'get colour of cells
FindP = .Cells(4, 2).Offset(r, c).Interior.ColorIndex
FindW = .Cells(10, 2).Offset(r, c).Interior.ColorIndex
'find value of colour (pasture and weed)
PGrowth = PastureVal(FindP)
WGrowth = WeedVal(FindW)
'paste back data where required
.Cells(16, 2 + i) = PGrowth
.Cells(17, 2 + i) = WGrowth
'make sure that cells moves
i = i + 1
End With
Next c
Next r
End Sub
Function PastureVal(Find As Double)
Dim val(6) As Double
Dim PVal(6) As Double
Dim k As Integer
Dim res As Double
'set data sets (color and value of pasture growth)
With Worksheets("trial")
For k = 0 To 6
val(k) = .Range("r3").Offset(k, 0).Interior.ColorIndex
PVal(k) = .Range("s3").Offset(k, 0)
Next k
End With
'find correct colour and value
Select Case Find
Case val(0)
res = PVal(0)
Case val(1)
res = PVal(1)
Case val(2)
res = PVal(2)
Case val(3)
res = PVal(3)
Case val(4)
res = PVal(4)
Case val(5)
res = PVal(5)
Case val(6)
res = PVal(6)
End Select
PastureVal = res
End Function
Function WeedVal(Find As Double)
'same as above
End Function
|