Excel 2003, triggering a result from a colour ?

Pauljj

Well-known Member
Joined
Mar 28, 2004
Messages
2,047
An early stage question but if I for example format A1 Green, is it possible that, from a pre-definded list of colours I can say Green = Job A, so the word Job A appears as a text value in for example C1

...and If I formatted A1 Yellow and Yellow meant Job C, that Job C appeared in C1 ?

Many thanks
Paul
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Well I'd never done this before, but I cobbled this code together from something similar I'd done before.

This code looks at a small range of cells, some of which I had previously coloured a shade of blue (specified by color index 42), and then writes the word "BLUE" into the cells that are shaded blue

Code:
Sub Apply_text_based_on_colour()
    Dim Cell As Range
    Dim Rng1 As Range
    Range("G13:G25").Select
    Set Rng1 = Selection
    For Each Cell In Rng1
        Select Case Cell.Interior.ColorIndex
        Case 42
            Cell.Value = "BLUE"
        End Select
    Next
End Sub
 
Upvote 0
Don't forget that you can do this the other way round, using Conditional Formating.

For example, you can make the cell have a colour, based on the text that is in it (or that is in some other cell).

It sounds as if you are planning to go to each cell, apply a colour to it, and then get the text to be input automatically.
That's fine, but it might be just as easy to go to each cell, manually input the text to it, and then get the colour applied automatically through CF.
 
Upvote 0
Something Similar !!
Code:
Private [COLOR="Navy"]Sub[/COLOR] Worksheet_SelectionChange(ByVal Target [COLOR="Navy"]As[/COLOR] Range)
[COLOR="Navy"]Dim[/COLOR] Jobs
[COLOR="Navy"]Dim[/COLOR] n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Integer[/COLOR]
Jobs = Array(vbGreen, "Jobs1", vbRed, "Job2", vbYellow, "Job3", vbBlue, "Job4", vbMagenta, "Job5", vbCyan, "Job6")
[COLOR="Navy"]For[/COLOR] n = 0 To UBound(Jobs)
    [COLOR="Navy"]If[/COLOR] Range("A1").Interior.Color = Jobs(n) [COLOR="Navy"]Then[/COLOR]
        Range("c1") = Jobs(n + 1)
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] n
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Hello Gerald, I think this is very similar to what I will need. Your code will add text to the cell that is formatted but what I will need is to format another cell. As example

A1 = Blue Then K1 = Job 1
A2= Yellow Then K2 = Job 4
A3 = Blue Then K3 = Job 1
A4 = Green Then K4 + job 5

B1 = Orange Then L1 = Job 3


and so on....does this make sense ?
 
Upvote 0
Maybe this ?
Code:
Sub Apply_text_based_on_colour()
    Dim Cell As Range
    Dim Rng1 As Range
    Range("G13:G25").Select
    Set Rng1 = Selection
    For Each Cell In Rng1
        Select Case Cell.Interior.ColorIndex
        Case 42
            Cell.Offset(rowoffset:=0, columnoffset:=10).Value = "BLUE"
           End Select
    Next
End Sub

Change the column offset value if it's not putting it in the right column.
 
Upvote 0
Something Similar !!
Code:
Private [COLOR="Navy"]Sub[/COLOR] Worksheet_SelectionChange(ByVal Target [COLOR="Navy"]As[/COLOR] Range)
[COLOR="Navy"]Dim[/COLOR] Jobs
[COLOR="Navy"]Dim[/COLOR] n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Integer[/COLOR]
Jobs = Array(vbGreen, "Jobs1", vbRed, "Job2", vbYellow, "Job3", vbBlue, "Job4", vbMagenta, "Job5", vbCyan, "Job6")
[COLOR="Navy"]For[/COLOR] n = 0 To UBound(Jobs)
    [COLOR="Navy"]If[/COLOR] Range("A1").Interior.Color = Jobs(n) [COLOR="Navy"]Then[/COLOR]
        Range("c1") = Jobs(n + 1)
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] n
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick

Perfect Mick, this is what I need, do you know if this will work across multiple cells. My range for colouring is C7:C50 with the jobs then appearing in M7: M50
 
Upvote 0
Obviously (well, perhaps not obviously :-) ) you can adapt my code to deal with lots of colours at the same time...
Code:
Sub Apply_text_based_on_colour()
Dim Cell As Range
Dim Rng1 As Range
Range("G13:G25").Select
Set Rng1 = Selection
For Each Cell In Rng1
Select Case Cell.Interior.ColorIndex
Case 42
Cell.Offset(rowoffset:=0, columnoffset:=10).Value = "BLUE"
Case 43
Cell.Offset(rowoffset:=0, columnoffset:=10).Value = "other colour 1"
Case 87
Cell.Offset(rowoffset:=0, columnoffset:=10).Value = "other colour 2"
End Select
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,634
Members
452,934
Latest member
Jdsonne31

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