I have 2 worksheets that I’m trying an index/match.
Sheet1 has a column of data (color hex #’s) starting in K2 and goes down (presently at 8 rows) (last row is defined as ‘ LRselected’)
Sheet3 has a 2 columns of data listing color names starting in A2 and corresponding Hex numbers in B2 and goes down (presently at 30282 rows) (last row is defined as ‘ Lastr3’)
My code for the last rows is
My experimental code for the index/match is
This code matches the hex number listed on Sheet1 in column “K” with Sheet3 column “B” and gives the Color Name from Sheet3 column “A” into column “P” on Sheet1 , but it gives the match from the last value in column “K” into all cells in column “P”.
I'm trying to get a match for EACH value listed in "K" but it returns only match for the last value in "K'.
Do I need to add/modify this code or use something totally different?
Sheet1 has a column of data (color hex #’s) starting in K2 and goes down (presently at 8 rows) (last row is defined as ‘ LRselected’)
Sheet3 has a 2 columns of data listing color names starting in A2 and corresponding Hex numbers in B2 and goes down (presently at 30282 rows) (last row is defined as ‘ Lastr3’)
My code for the last rows is
VBA Code:
With Sheet1
Dim Lastr1 As Long
Lastr1 = .Range("C" & .Rows.Count).End(xlUp).Row 'presently at 2863
Dim LRselected As Long
LRselected = .Range("K" & .Rows.Count).End(xlUp).Row 'presently at 8
End With
With Sheet3
Dim Lastr3 As Long
Lastr3 = .Range("A" & .Rows.Count).End(xlUp).Row 'presently at 30282
End With
My experimental code for the index/match is
VBA Code:
Dim CLL1 As Range
Dim r As Long
For r = 2 To LRselected
For Each CLL1 In Sheet1.Range("K2:K" & LRselected).Rows
If CLL1.Value <> "" Then
CLL1.Offset(0, 5).Value = WorksheetFunction.Index(Sheet3.Range("A2:A" & Lastr3), WorksheetFunction.Match(Sheet1.Cells(r, "K"), Sheet3.Range("B2:B" & Lastr3), 0))
End If
If CLL1.Value = "" Then
CLL1.Offset(0, 5).Value = ""
End If
Next
This code matches the hex number listed on Sheet1 in column “K” with Sheet3 column “B” and gives the Color Name from Sheet3 column “A” into column “P” on Sheet1 , but it gives the match from the last value in column “K” into all cells in column “P”.
I'm trying to get a match for EACH value listed in "K" but it returns only match for the last value in "K'.
Do I need to add/modify this code or use something totally different?