ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Change cells color & cells contains if formula (https://www.excelbanter.com/excel-programming/351303-change-cells-color-cells-contains-if-formula.html)

dot[_2_]

Change cells color & cells contains if formula
 
I'm new to excel vba. I'm tried out the vba code for changing cells
color but it don't work if my cells contains a if formula (eg. all
cells in cloumn A contain =if(and(b1="Rej",c1="Rej"),"Rej",....). Any
idea what should be the code?


Kevin B

Change cells color & cells contains if formula
 
Perhaps this little code snippet will point you in the right direction:

Sub FormulaCellColor()

Dim varVal As Variant
Dim strCell As String
Dim r As Range

Range("A1").Select
varVal = ActiveCell.Value

Do Until varVal = ""
Set r = ActiveCell
If r.HasFormula Then
With r
.Interior.Color = vbBlue
.Font.Color = vbWhite
End With
End If
ActiveCell.Offset(1).Select
Loop

Set r = Nothing

End Sub


--
Kevin Backmann


"dot" wrote:

I'm new to excel vba. I'm tried out the vba code for changing cells
color but it don't work if my cells contains a if formula (eg. all
cells in cloumn A contain =if(and(b1="Rej",c1="Rej"),"Rej",....). Any
idea what should be the code?




All times are GMT +1. The time now is 06:49 AM.

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