Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Diagonal Borders in a Conditional Format.
Written by Allen Wyatt (last updated January 13, 2021)
This tip applies to Excel 97, 2000, 2002, and 2003
Parin likes using the diagonal border on some cells to show the value as "crossed out." She would like to use diagonal borders in a conditional format, however. When she tries, she can set other types of borders, but not a diagonal border—it is not selectable in the conditional format. She wonders if there is a way to use diagonal borders with conditional formats.
There is no direct way to do this when setting up a conditional format—Excel simply won't allow you to use diagonal borders with a conditional format. That means that you may want to look for and use an acceptable workaround. Here are a few ideas for the conditional format:
If you actually want to use the diagonal borders, then the only way to do it is to apply an explicit format to the cell and not rely on a conditional format. This can be done through the use of a macro, such as the following:
Private Sub Worksheet_Change(ByVal Target As Range) Dim c As Variant Dim addr As String Set Target = Range("C12:C20") If Intersect(Target, ActiveCell) Is Nothing Then Exit Sub For Each c In Target If c = 0 And Len(c) <> 0 Then addr = c.Address With Range(addr).Borders(xlDiagonalUp) .LineStyle = xlContinuous End With ElseIf c > 0 And Len(c) > 0 Then addr = ActiveCell.Address With Range(addr).Borders(xlDiagonalUp) .LineStyle = xlNone End With End If Next End Sub
You should right-click on a worksheet tab, display the code window from the resulting Context menu, and then paste this macro into the code window. The macro is executed any time a cell is changed in the worksheet. It checks the cells in C12:C20, and if any of them contain a zero value, then the diagonal border is set for that cell.
You can easily change the macro to apply to a different range of cells or to check for a different condition when applying the borders. If you prefer, you can change the xlDiagonalUp constant to xlDiagonalDown, depending on which diagonal border you want applied.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10692) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Diagonal Borders in a Conditional Format.
Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!
There are many times when you are creating a worksheet that you need to analyze dates within that worksheet. Once such ...
Discover MoreConditional formatting can be used to draw your attention to certain cells based on what is within those cells. This tip ...
Discover MoreIf you want to apply a conditional format to data imported into Excel from Access, you may run into some difficulties ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2020-06-26 15:12:02
Mark Ellis
This is close to what I need... but more specifically, if value = 0 then diagonal down, if value = 1 then diagonal up, if value = 2 then vertical side, if value <> 0, 1, 2 then nothing.
2016-08-04 14:23:08
Carol Terrell
Please help.
This is a question related to the Format.
Can you have different size data in the spread sheet on the same row?
Example;
I have sales data from Jan to Dec for 2016, 2015 & 2014 on the first half of my excel workbook across the top.
Now I want to have different months and years with different data under this data using the same cell rows as the top but these cells I need in a different size than the top cells but still on the same rows.
Is that possible? Can I format the bottom to any size within that row and still have it all on the same row and be able to change fronts, etc. without adjusting the top row? Please email me an answer.
Thank You.
Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments