VBA code

The Idea Dude

Well-known Member
Joined
Aug 15, 2002
Messages
591
Office Version
  1. 2016
Platform
  1. Windows
What code would do the following?

There are 5 numbers in different cells (These numbers can change)

A1=2,
A2=6,
A3=9,
A4=35,
A5=3

I need to allocate one colour to the highest number, a different colour to the next highest and so on.

Any suggestions?
This message was edited by The Idea Dude on 2002-09-11 03:49
 
Well, the Change event only occurs when a user changes a cell and a combo box is not a user!

So you need to delete the Worksheet_Change procedure and add this:

Code:
Private Sub ComboBox1_Change()
    Call Colours
End Sub
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
So it looks like this? (the combo box is #17)

Private Sub ComboBox17_Change(ByVal Target As Range)
If Target.Address <> "$R$17" Then Exit Sub
Application.EnableEvents = False
Call Colours
Application.EnableEvents = True
End Sub

I must still be doing something wrong because it is not working yet:)
 
Upvote 0
OK Andrew I think I have this nailed, the colours are changing now, however, if I click colours off, and then change the dropdown box, as expected, colours re-appear.

Here is my attempt at stopping this:)
And guess what, it didn't work:)

What's my error

Range("Bll").Select
If Selection.Font.ColorIndex = 1 Then
Range("A1").Select
Else
Call Colours
End If
End Sub

Thanks again,

It is because of people like you that makes learning this stuff so much more fun and easy!!!
This message was edited by The Idea Dude on 2002-09-12 04:54
 
Upvote 0
I think you are missing my bit of code that tests if the colour is 1.

Code:
' * You already have the next line *
Set Rng = Range("B11:B15")
' * You are missing these lines *
    For Each c In Rng
        If c.Font.ColorIndex = 1 Then Exit Sub
    Next c
' * You already have the next line *
    For Each c In Rng
' * etc etc etc
 
Upvote 0

Forum statistics

Threads
1,215,008
Messages
6,122,672
Members
449,091
Latest member
peppernaut

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