Select Case Range

Faygin

New Member
Joined
May 12, 2020
Messages
23
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I am trying to examine a whole range of cells.
And depedning on which number the cell has in it, it should have a colouring.

VBA Code:
Select Case Range("T2:AD900").Value

Case 0
ActiveCell.Interior.Color = xlNone

Case 1
ActiveCell.Interior.Color = RGB(255, 153, 0)

Case 2
ActiveCell.Interior.Color = RGB(51, 204, 204)

Case 3
ActiveCell.Interior.Color = RGB(255, 204, 204)

Case 4
ActiveCell.Interior.Color = RGB(255, 255, 153)

Case 5
ActiveCell.Interior.Color = RGB(204, 255, 255)

Case 6
ActiveCell.Interior.Color = RGB(255, 204, 0)

Case 7
ActiveCell.Interior.Color = RGB(192, 192, 192)

Case 8
ActiveCell.Interior.Color = RGB(150, 150, 150)

Case 9
ActiveCell.Interior.Color = RGB(0, 128, 128)

Case 10
ActiveCell.Interior.Color = RGB(205, 204, 255)

Case 14
ActiveCell.Interior.Color = RGB(205, 204, 255)

Case Else
ActiveCell.Interior.Color = RGB(0, 0, 0)

End Select

I get a type mismatch error.
It seems like its something wrong with: Select Case Range("T2:AD900").Value

Because of i change to Select Case Range("T2").Value and just test 1 cell it seem to work.

Made some other attempts as well, but then all cells get coloured in the first criteria being met.

Please advice! Thank you for your help.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Forum statistics

Threads
1,215,772
Messages
6,126,801
Members
449,337
Latest member
BBV123

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