ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Conditional Formatting? (https://www.excelbanter.com/excel-programming/346899-conditional-formatting.html)

Zlord[_5_]

Conditional Formatting?
 

Alright, we all know how conditional formatting works.


Code:
--------------------

Range("F113:F127").Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=($D130=5)"
Selection.FormatConditions(1).Interior.ColorIndex = 50

--------------------


That's an example of what I want.
Doing that; The Collumn "D" stays the same; but the row increases
incrementally.
How would I code something exactly like conditional formatting in VBA?
Where it is able to use all of the excel formulas and everything.

Why I want to know -- I'm using some conditional formatting, but I need
more than the 3 built in choices.

Thanks
~Ryan


--
Zlord
------------------------------------------------------------------------
Zlord's Profile: http://www.excelforum.com/member.php...o&userid=27519
View this thread: http://www.excelforum.com/showthread...hreadid=489279


Martijn[_2_]

Conditional Formatting?
 
Zlord,

Try this, modify it to your workbook.

Sub Macro1()

Dim cell As Range
Dim eRow As Long

eRow = Range("F2").End(xlDown).Row

For Each cell In Range("F2:F" & eRow)
Select Case cell.Value
Case 0
cell.Interior.ColorIndex = 3
Case 1
cell.Interior.ColorIndex = 6
Case 2
cell.Interior.ColorIndex = 5
Case 3
cell.Interior.ColorIndex = 8
-----
and so on
case .....
cell.Interior.ColorIndex = .....
-----

Case Else
cell.Interior.ColorIndex = xlNone
End Select
Next cell

End Sub


Good luck with it,

grtx's Martijn

"Zlord" schreef in
bericht ...

Alright, we all know how conditional formatting works.


Code:
--------------------

Range("F113:F127").Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlExpression,

Formula1:="=($D130=5)"
Selection.FormatConditions(1).Interior.ColorIndex = 50

--------------------


That's an example of what I want.
Doing that; The Collumn "D" stays the same; but the row increases
incrementally.
How would I code something exactly like conditional formatting in VBA?
Where it is able to use all of the excel formulas and everything.

Why I want to know -- I'm using some conditional formatting, but I need
more than the 3 built in choices.

Thanks
~Ryan


--
Zlord
------------------------------------------------------------------------
Zlord's Profile:

http://www.excelforum.com/member.php...o&userid=27519
View this thread: http://www.excelforum.com/showthread...hreadid=489279




Zlord[_6_]

Conditional Formatting?
 

I tried this; didn't work, any ideas how I would do something where when
the case is one of those, then it will color the cells A,strin through
K,strin as a specific color?:confused:


Code:
--------------------

Private Sub Worksheet_Change(ByVal Target As Range)
Dim eRow As Integer
Dim strin As Integer
eRow = Range("K2").End(xlDown).Row
strin = 3
For Each cell In Range("K3:K" & eRow)
Select Case cell.Value
Case (cell(K, strin) = "ADMIN. REQUEST") Or (cell(K, strin) = "PARENT REQUEST")
Cells(A, strin).Interior.ColorIndex = 3
Case (cell(K, strin) = "EATING") Or (cell(K, strin) = "INSUBORDINATION")
Row.Interior.ColorIndex = 7
Case (Cells("K19") = "")
Selected.Row.Interior.ColorIndex = 5
Case Else
Row.Interior.ColorIndex = 9
End Select
strin = strin + 1
Next
End Sub

--------------------


--
Zlord
------------------------------------------------------------------------
Zlord's Profile: http://www.excelforum.com/member.php...o&userid=27519
View this thread: http://www.excelforum.com/showthread...hreadid=489279


Zlord[_7_]

Conditional Formatting?
 

not yet answered


--
Zlord
------------------------------------------------------------------------
Zlord's Profile: http://www.excelforum.com/member.php...o&userid=27519
View this thread: http://www.excelforum.com/showthread...hreadid=489279



All times are GMT +1. The time now is 07:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com