Dynamic line numbering when rows get added or swapped

BlackieHamel

Board Regular
Joined
May 9, 2014
Messages
93
I have a simple table with line numbers (1,2,3. . .x) appearing in Column A. Cell A1 is 1, Cell A2's formula is A1+1, Cell A3's formula is A2+1, and so on. This creates problems if anything gets moved.

What is a good way to keep the line numbers sequential when a row gets added, deleted, or moved?

Thanks -- Blackie
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
If you just want row numbers starting at 1, then place this formula in cell A1 and copy down:
Code:
=ROW()
 
Upvote 0
You are welcome!

The key is to not put any argument between the (). The defaults to the current row number that the formula is found in.
 
Upvote 0
You are welcome!

The key is to not put any argument between the (). The defaults to the current row number that the formula is found in.

Okay, here's a more ambitious task. My table has shading in the even-numbered rows. I tried to do that by selecting the whole table and setting Conditional Formatting with the formula to apply shading if
Code:
=iseven(row())

But when I add a row, that shades the entire table below the insertion. Can you see what I'm doing wrong?
 
Upvote 0
But when I add a row, that shades the entire table below the insertion. Can you see what I'm doing wrong?
No, that shouldn't be possible, based on that one rule.
Are you sure that you don't have any other Conditional Formatting rules lingering out there?
 
Upvote 0
No, I am not experienced with Conditional Formatting, so I'm quite sure there are no other rules there. But as I think about it, it seems like I need an IF statement: if the row number is even, apply shading; if the row number is even, use a white (non-shaded) background.

And you gave me an idea when you suggested that there can be multiple Conditional Formatting rules affecting the same range. I tried to select the whole table and apply two Conditional formatting rules, but still, when I add a row, it seems to just keep the shading of the row above.

Blackie
 
Upvote 0
it seems like I need an IF statement: if the row number is even, apply shading; if the row number is even, use a white (non-shaded) background.
No, you don't need an IF, and you do not need multiple rules - just one, if you want to shade every other row (and leave the others "as-is").
You would only need two rules if you wanted to colors (and neither one the standard white background).

Try this:
1. Remove ALL Conditional Formatting from your Sheet
2. Select all the rows you might ever use
3. Entering the following CF rule:
Code:
=ISEVEN(ROW())
4. Choose the formatting shading color that you want
5. Click OK

*Also make sure that the Calculation mode on your worksheet is set to Automatic.

If you insert rows WITHIN this range which has been Conditionally Formatted, the new rows should inherit this rule, and everything should continue to work.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,190
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top