![]() |
Functon to fill cell with color
I know this has been asked before but I could not find a good answer
searching the archives. I have a function that uses multiple IF-Then Statements. I want to return text and a fill color to the cell based on these logical condtions. I have about 20 logical statements to the Conditional Formating will not work. What are the basic code statements for this color fill? Thanks Steve |
Functon to fill cell with color
Heres a small worked solution for filling colour on specific text. Just paste this code into the sheet your using and modify! Hope it helps! Simon Sub people() Dim rng Dim mycell Set rng = Range("A1:H20") For Each mycell In rng If mycell = "Fred" Then f ElseIf mycell = "Bob" Then B ElseIf mycell = "john" Then J ElseIf mycell = "" Then Exit Sub End If Next mycell End Sub Sub f() With Selection.Interior ..ColorIndex = 3 ..Pattern = xlSolid ..PatternColorIndex = xlAutomatic End With End Sub Sub J() With Selection.Interior ..ColorIndex = 12 ..Pattern = xlSolid ..PatternColorIndex = xlAutomatic End With End Sub Sub B() With Selection.Interior ..ColorIndex = 22 ..Pattern = xlSolid ..PatternColorIndex = xlAutomatic End With End Sub -- Simon Lloyd ------------------------------------------------------------------------ Simon Lloyd's Profile: http://www.excelforum.com/member.php...fo&userid=6708 View this thread: http://www.excelforum.com/showthread...hreadid=490047 |
Functon to fill cell with color
You use the Range Objects Interior.Color or Interior.ColorIndex
Property. eg... Application.ActiveCell.Interior.Color = vbYellow |
All times are GMT +1. The time now is 01:54 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com