![]() |
Conditional Formatting in a Macro
Hello I have the following Macro:
Sub Comma() Range("K3").Select Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select Selection.Style = "Comma" End Sub How can I add maybe after Selection.Style a line into this Macro with a Conditional Formating that IF $B3 is equal to "1" then I want to have a Black cell shading and White Arial Bold font style. thanks! |
Conditional Formatting in a Macro
Hi Ed,
If you want to add conditionnal formatting with your macro Selection.FormatConditions.Add If you want to test Range("B3").Value and then apply format changes With Selection.Interior .ColorIndex = 1 End With With Selection.Font .Name = "Arial Narrow" .FontStyle = "Normal" .ColorIndex = 2 End With HTH Carim |
Conditional Formatting in a Macro
Hello Carim, sorry I didn't got how this code that you sent me works!
Anyways... I think I didn't explain myself well on the previous post... the idea is to have a macro which takes "$K$3" from the sheet and my idea was to drag a Conditional Formatting up to the Last Row and Column of that Table, I already have it set up to give a "Comma" format, but I would like to add the CF I mentioned before. The formula for the CF would be =$B3=1, What I mean with that is that if $B3 has "1" in it, the entire row 3 would be black and so on... but if $B4 doesn't have "1", the entire row stays as it is, and so on... This code: Range("K3").Select Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select Selection.Style = "Comma" End Sub I got it just though a simple "Record Macro", but I would like to add the CF part into it... thanks again! "Carim" wrote: Hi Ed, If you want to add conditionnal formatting with your macro Selection.FormatConditions.Add If you want to test Range("B3").Value and then apply format changes With Selection.Interior .ColorIndex = 1 End With With Selection.Font .Name = "Arial Narrow" .FontStyle = "Normal" .ColorIndex = 2 End With HTH Carim |
All times are GMT +1. The time now is 08:24 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com