Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Automatic Lines for Dividing Lists.

Automatic Lines for Dividing Lists

by Allen Wyatt
(last updated April 5, 2018)

6

Let's say you have a list of company transactions. Each transaction includes a department number, a title, and other information (amount, date, authorizer, etc.). As you get more and more of these items in your list, you may want a way to automatically add "dividing lines" based on the department number. For instance, when the department number changes, you may want to include a line between the two departments.

To add this type of formatting to your list, start by sorting your data table by department. For the sake of this example, I'll assume that your data is actually in columns A:F, with the department numbers in column A. (See Figure 1.)

Figure 1. The data to be divided.

To add the automatic dividing lines, follow these steps:

  1. Select the left-most cell of the first row of your data. For instance, if your table heads are in row 3 and your first row of data is in row 4, you should select cell A4.
  2. Press Shift+Ctrl+End. All the cells in your data table should be selected, with the exception of the header row.
  3. With the Home tab of the ruler displayed, click the Conditional Formatting option in the Styles group. Excel displays a palette of options related to conditional formatting.
  4. Click New Rule. Excel displays the New Formatting Rule dialog box.
  5. In the Select a Rule Type area at the top of the dialog box, choose Use a Formula to Determine Which Cells to Format. (See Figure 2.)
  6. Figure 2. The New Formatting Rule dialog box.

  7. In the Format Values Where This Formula Is True box, enter "=$A4<>$A5" (without the quote marks). This formula, of course, will vary depending on your data. As entered here, it is appropriate for the data table already described in this tip and the cell selected in step 1.
  8. Click Format to display the Format Cells dialog box.
  9. Display the Border tab.
  10. Click the None button to remove any borders already applied to the cells.
  11. In the Style list, select the type of border you want to appear between departments.
  12. In the Border area of the dialog box, click the button that adds your selected border style to the bottom of the cells.
  13. Click OK to dismiss the Format Cells dialog box. The formatting you specified in steps 10 and 11 should now appear in the preview area for the rule.
  14. Click OK.

That's it; you should now see a line that appears across the entire width of your data every time the department changes.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (6863) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Automatic Lines for Dividing Lists.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Protecting Hidden Text

Formatting some of your text as hidden can be a great help when you need to keep some things from being viewed or ...

Discover More

Finding Columns of a Certain Width

If you need to find out how many columns are set to be a specific width, you'll need a macro to help determine the info. ...

Discover More

Opening a Workbook as Read-Only

When you need to work on a workbook, you may want to do so without modifying the original contents of the workbook. This ...

Discover More

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!

More ExcelTips (ribbon)

Conditional Formatting Based on Date Proximity

Conditional formatting can be used to draw your attention to certain cells based on what is within those cells. This tip ...

Discover More

Conditional Format that Checks for Data Type

Conditional formatting can be used to highlight cells that contain the improper type of data for your needs. This tip ...

Discover More

Returning a Value Based on Text Color

Conditional formatting rules can be used to adjust the way in which information is displayed in Excel, such as the text ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is seven more than 2?

2018-04-06 14:23:43

Ronmio

On my computer (Windows 10, Office 2013), Ctrl+Shift+End does SELECT the range. It is the equivalent of F8 followed by Ctrl+End. However, Ctrl+End alone just moves the cursor.


2018-04-06 01:15:18

Ronmio

I find it easier, faster, and more universal to use this approach ...

1. Select all the columns where you want the separation lines to appear.
2. < omit step 2 >
.
.
.
6. In the Format Values Where This Formula Is True box, enter "=AND(ROW()>=4,$A1<>$A2)" (without the quote marks). This formula, of course, will vary depending on your data: you only need to change the "ROW()>= 4" to refer to the first data row, and change the column letter in "$A1<>$A2" to refer to the column that is to trigger the separation line . As shown here, the formula is appropriate for where the first data row is row 4 and the data that is to trigger the separation line is in column A like the data table already described in this tip.
.
.
.
< complete steps 7-13 >


2018-04-05 17:03:12

Robert

Ctrl+Shft+End only moves the curser, it does not select all the data.


2018-04-05 15:21:13

Ronmio

I find it easier, faster, and more universal to use this approach ...

1. Select all the columns where you want the separation lines to appear.
2. < omit step 2 >
.
.
.
6. In the Format Values Where This Formula Is True box, enter "=AND(ROW()>=4,$A1<>$A2)" (without the quote marks). This formula, of course, will vary depending on your data: you only need to change the "ROW()>= 4" to refer to the first data row, and change the column letter in "$A1<>$A2" to refer to the column that is to trigger the separation line . As shown here, the formula is appropriate for where the first data row is row 4 and the data that is to trigger the separation line is in column A like the data table already described in this tip.
.
.
.
< complete steps 7-13 >


2017-01-04 08:57:45

Dee

Any way you can make the dividing lines bold or thicker?


2016-03-24 16:55:43

Connie

At last - thank you!! A lot of other sites have the formula backward.


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.