If Index/Match value is less than not working

KDS14589

Board Regular
Joined
Jan 10, 2019
Messages
180
Office Version
  1. 2016
Platform
  1. Windows
I have a list of numbers between 0 to 100 in column L. And a list of items in column O. What I'm trying to do is if that single item has a 'lightness' number less or equal to 50 then the font in certain cells change color.
I need another set of eyes because I cannot get it to work or another approach.



VBA Code:
Dim Item As Range    'single Item
Dim Lightness As Range   'Lightness list
Set Lightness = ShGE03.Range("L5", ShGE03.Range("L" & ShGE03.Rows.Count).End(xlUp))
Dim List As Range   'List of items
Set List = ShGE03.Range("O5", ShGE03.Range("O" & ShGE03.Rows.Count).End(xlUp))

Set Item = ShGE03.Range("A5")    'single item
If WorksheetFunction.Index(Lightness, WorksheetFunction.Match(Item, List, 0)).Value <= 50 Then
Range("A1:A4").Font.Color = vbWhite
Range("A37:A38").Font.Color = vbWhite
Range("A47:A48").Font.Color = vbWhite
Else
Range("A1:A4").Font.Color = vbBlack
Range("A37:A38").Font.Color = vbBlack
Range("A47:A48").Font.Color = vbBlack
End If
/CODE]
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Hi,

Have you already tested
VBA Code:
If WorksheetFunction.Index(Lightness, WorksheetFunction.Match(Item, List, 0)) <= 50 Then
 
Upvote 0
Your code is running fine for me with the data set below A1:A4 on the Activesheet the font changes to black when I have G in A5 and changes to white when I have B in A5 (all I changed to test was ShGE03 to ActiveSheet so it was all on the same sheet and put in a debug.print line to check the value returned)

I can't tell if ShGE03 is the issue here as you haven't posted where you define the sheet.

Book1.xlsb
ABLMNO
1R
2S
3T
4U
5G45A
643B
712C
825D
947E
1036F
1179G
1214H
1312I
143J
1516K
167L
1714M
1856N
Sheet3


Edit: now also tested with defining ShGE03 as a different sheet and it still changes the A1:A4 cells on the Activesheet
 
Last edited:
Upvote 1
Solution
Your code is running fine for me with the data set below A1:A4 on the Activesheet the font changes to black when I have G in A5 and changes to white when I have B in A5 (all I changed to test was ShGE03 to ActiveSheet so it was all on the same sheet and put in a debug.print line to check the value returned)

I can't tell if ShGE03 is the issue here as you haven't posted where you define the sheet.

Book1.xlsb
ABLMNO
1R
2S
3T
4U
5G45A
643B
712C
825D
947E
1036F
1179G
1214H
1312I
143J
1516K
167L
1714M
1856N
Sheet3


Edit: now also tested with defining ShGE03 as a different sheet and it still changes the A1:A4 cells on the Acti

Your code is running fine for me with the data set below A1:A4 on the Activesheet the font changes to black when I have G in A5 and changes to white when I have B in A5 (all I changed to test was ShGE03 to ActiveSheet so it was all on the same sheet and put in a debug.print line to check the value returned)

I can't tell if ShGE03 is the issue here as you haven't posted where you define the sheet.

Book1.xlsb
ABLMNO
1R
2S
3T
4U
5G45A
643B
712C
825D
947E
1036F
1179G
1214H
1312I
143J
1516K
167L
1714M
1856N
Sheet3


Edit: now also tested with defining ShGE03 as a different sheet and it still changes the A1:A4 cells on the Activesheet
I changed my code to that ‘ActiveSheet’ and now the code works. Even though the ActiveSheet is the same as ShGE03, that is just the codename for that sheet. Before I did the renaming, I updated my version. So, I don’t know for sure if it was the ‘ActiveSheet’ or a corrupt excel, but either way it is working now.

Thanks for the help.
 
Upvote 0
More likely a corrupt file as no reason why it would error if the variable was defined correctly.

You're welcome and happy you have it sorted
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top