Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 386
Default Colour Index

Hi,

Sorry yet another simple question.

I have numbers, (1,2,3 etc) in cells I5 to I9 from which I would like to
generate a colour in cells B5-9, (black, white, red etc). If I change I6
from 4 to 9 the colour in B6 updates as soon as I hit return or the down key
after entering the number.

What is the easiest way to do this?
Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default Colour Index

You need an event sub for that:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row = 5 And Target.Row <= 9 And Target.Column = 9 Then
Range("B" & Target.Row).Font.ColorIndex = Target
End If
End Sub


Regards,
Stefi

€˛LiAD€¯ ezt Ć*rta:

Hi,

Sorry yet another simple question.

I have numbers, (1,2,3 etc) in cells I5 to I9 from which I would like to
generate a colour in cells B5-9, (black, white, red etc). If I change I6
from 4 to 9 the colour in B6 updates as soon as I hit return or the down key
after entering the number.

What is the easiest way to do this?
Thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Colour Index

Enter the following event macro in the worksheet code area:

Private Sub Worksheet_Change(ByVal Target As Range)
Set i = Range("I5:I9")
Set t = Target
If Intersect(t, i) Is Nothing Then Exit Sub
v = t.Value
If v 56 Then Exit Sub
Application.EnableEvents = False
Cells(t.Row, "B").Interior.ColorIndex = v
Application.EnableEvents = True
End Sub

so if you enter a number between 1 and 56 in column I, the cell in column B
will change to that number.


Because it is worksheet code, it is very easy to install and use:

1. right-click the tab name near the bottom of the window
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window

If you save the workbook, the macro will be saved with it.

To remove the macro:

1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm


--
Gary''s Student - gsnu200830


"LiAD" wrote:

Hi,

Sorry yet another simple question.

I have numbers, (1,2,3 etc) in cells I5 to I9 from which I would like to
generate a colour in cells B5-9, (black, white, red etc). If I change I6
from 4 to 9 the colour in B6 updates as soon as I hit return or the down key
after entering the number.

What is the easiest way to do this?
Thanks

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 386
Default Colour Index

Hi,

Sorry I should have been more specific.

I was hoping to colour the cell and the text. How do I adapt the code to do
both?

Thanks

"Stefi" wrote:

You need an event sub for that:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row = 5 And Target.Row <= 9 And Target.Column = 9 Then
Range("B" & Target.Row).Font.ColorIndex = Target
End If
End Sub


Regards,
Stefi

€˛LiAD€¯ ezt Ć*rta:

Hi,

Sorry yet another simple question.

I have numbers, (1,2,3 etc) in cells I5 to I9 from which I would like to
generate a colour in cells B5-9, (black, white, red etc). If I change I6
from 4 to 9 the colour in B6 updates as soon as I hit return or the down key
after entering the number.

What is the easiest way to do this?
Thanks

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default Colour Index

You can set the background color this way
Range("B" & Target.Row).Interior.ColorIndex = Target

But in one cell (I5:I9) you can have only one ColorIndex. Setting both
foreground and background color to the same value makes the cell content
invisible.

Regards,
Stefi

€˛LiAD€¯ ezt Ć*rta:

Hi,

Sorry I should have been more specific.

I was hoping to colour the cell and the text. How do I adapt the code to do
both?

Thanks

"Stefi" wrote:

You need an event sub for that:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row = 5 And Target.Row <= 9 And Target.Column = 9 Then
Range("B" & Target.Row).Font.ColorIndex = Target
End If
End Sub


Regards,
Stefi

€˛LiAD€¯ ezt Ć*rta:

Hi,

Sorry yet another simple question.

I have numbers, (1,2,3 etc) in cells I5 to I9 from which I would like to
generate a colour in cells B5-9, (black, white, red etc). If I change I6
from 4 to 9 the colour in B6 updates as soon as I hit return or the down key
after entering the number.

What is the easiest way to do this?
Thanks

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy rows with Interior Colour Index values 15 and 35 to a new she manfareed Excel Programming 7 January 19th 09 04:03 PM
Colour index Arran Excel Discussion (Misc queries) 10 December 7th 06 07:27 PM
Event Change on colour index Graham Haughs Excel Programming 1 November 15th 06 10:44 PM
colour index matrix DHallam Excel Discussion (Misc queries) 3 June 1st 06 06:53 PM
Are there apis that relate colour index with color? Jan Nordgreen Excel Programming 5 October 13th 03 12:37 AM


All times are GMT +1. The time now is 11:04 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"