LokaPoka
New Member
- Joined
- Aug 30, 2012
- Messages
- 6
This is my first-ever post to any forum so I hope I am following all the rules.
My question is actually the same as one previously posted on this forum, except that I am using Excel 2010, and the code posted for 2007 does not work for me. (The original poster said that he made some customizations, so perhaps the code also didn't work for him as-is.) I'm going to copy the text of the original poster, the answer that worked (?) for him, and a link to the original post.
Original post:
I'm wanting to dynamically set the RGB background color for cells in Column D to that of RGB values held in columns A,B,C. In other words, I am wanting to avoid achieving this by using Conditional Formatting with custom STYLES.
ie. A1=REDval, B1=GREENval, C1=BLUEval then cell backgroud color D1 = RGB(A1, B1, C1)
Example1:
A1=253, B1=205, C1=203
Then background RGB color of cell D1 to be automatically set to RGB(A1, B1, C1) = RGB(253, 205, 203)
Example2:
Background colour of Cell D1 = RGB("Value of A1","Value of B1","Value of C1")
Background colour of Cell D2 = RGB("Value of A2","Value of B2","Value of C2")
..
..
Background colour of Cell D65535 = RGB("Value of A65535","Value of B","Value of C65535")
I've tried looking for an answer but my keyword searches are either weak or inaccurate.
Any help or a solution would be most appreciated.
Original answer (for Excel 2007), and I apologize because I can't figure out how to make the code box (I searched the FAQ) but have done my best to simulate it for ease of reading:
In the worksheet where you want this colour banding to occur, right-click on the tab name at the bottom of Excel and select View Code. Paste the following into the code window which will open:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range, cell As Range
Dim i As Long
Set rng = Intersect(Target, Range("A:C"))
If Not rng Is Nothing Then
End Sub
Then go back into your sheet and enter some values in columns A:C. You will need a value in each of A:C on that particular row before the colour is applied in column D. If you already have a lot of values in A:C already, then select column A and go Ctrl+C>Ctrl+V to re-enter and thus apply the formatting to column D.
Link to original post:
http://www.mrexcel.com/forum/excel-...round-color-using-contents-3-other-cells.html
One thing I noticed is that the 2nd occurrence of "Application.CountA" does not have an "A", but adding the A does not make the code work for me. I get the error: "Compile error: Wrong number of arguments or invalid property assignment".
Thanks so much in advance!
~Katie
My question is actually the same as one previously posted on this forum, except that I am using Excel 2010, and the code posted for 2007 does not work for me. (The original poster said that he made some customizations, so perhaps the code also didn't work for him as-is.) I'm going to copy the text of the original poster, the answer that worked (?) for him, and a link to the original post.
Original post:
I'm wanting to dynamically set the RGB background color for cells in Column D to that of RGB values held in columns A,B,C. In other words, I am wanting to avoid achieving this by using Conditional Formatting with custom STYLES.
ie. A1=REDval, B1=GREENval, C1=BLUEval then cell backgroud color D1 = RGB(A1, B1, C1)
Example1:
A1=253, B1=205, C1=203
Then background RGB color of cell D1 to be automatically set to RGB(A1, B1, C1) = RGB(253, 205, 203)
Example2:
Background colour of Cell D1 = RGB("Value of A1","Value of B1","Value of C1")
Background colour of Cell D2 = RGB("Value of A2","Value of B2","Value of C2")
..
..
Background colour of Cell D65535 = RGB("Value of A65535","Value of B","Value of C65535")
I've tried looking for an answer but my keyword searches are either weak or inaccurate.
Any help or a solution would be most appreciated.
Original answer (for Excel 2007), and I apologize because I can't figure out how to make the code box (I searched the FAQ) but have done my best to simulate it for ease of reading:
In the worksheet where you want this colour banding to occur, right-click on the tab name at the bottom of Excel and select View Code. Paste the following into the code window which will open:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range, cell As Range
Dim i As Long
Set rng = Intersect(Target, Range("A:C"))
If Not rng Is Nothing Then
On Error Resume Next
For Each cell In Target.Columns(1).Cells
For Each cell In Target.Columns(1).Cells
If Application.CountA(Range("A" & cell.Row & ":C" & cell.Row)) < 3 Or _
Application.Count(Range("A" & cell.Row & ":C" & cell.Row)) < 3 Then GoTo next_row
Cells(cell.Row, "D").Interior.Color = _ RGB(Cells(cell.Row, "A").Value, Cells(cell.Row, "B").Value, Cells(cell.Row, "C").Value)
next_row: Next cell
End If End Sub
Then go back into your sheet and enter some values in columns A:C. You will need a value in each of A:C on that particular row before the colour is applied in column D. If you already have a lot of values in A:C already, then select column A and go Ctrl+C>Ctrl+V to re-enter and thus apply the formatting to column D.
Link to original post:
http://www.mrexcel.com/forum/excel-...round-color-using-contents-3-other-cells.html
One thing I noticed is that the 2nd occurrence of "Application.CountA" does not have an "A", but adding the A does not make the code work for me. I get the error: "Compile error: Wrong number of arguments or invalid property assignment".
Thanks so much in advance!
~Katie