How to renumber with merged cells?

Status
Not open for further replies.

Tussas

New Member
Joined
Sep 11, 2015
Messages
12
Hi all,

I have a database, where in column "B" of one of the worksheets some cells are merged (by
2, 3 or more) and some are not.
I want to number them in order that
every single or "group-of-merged-cells" cell will have just one number.

For example, 3rd + 4th are merged, 5th is single and 5th+6th+7th are merged. This way about 10000 rows in first column.
How to number them in order?

I already have a partial solution:

Sub numberCells()
Dim i As Long, j As Long
i = 1
j = 1
Do
If Cells(i, "B").MergeArea.Rows.Count > 1 Then
Cells(i, "B").Value = j
i = i + Cells(i, "B").MergeArea.Rows.Count
Else
Cells(i, "B").Value = j
i = i + 1
End If
j = j + 1
Loop Until j > 1000
End Sub


My problems:

1. Renumbering can only start in row 3. The first two rows are not numbered.
2. This is to be done only in one of the tabs called "Global List". This one will map the others through another macro.
3. It would be really nice if it would automatically run the macro with event "Insert row".

How can I adapt the code to it?

Thanks,
Tiago
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Status
Not open for further replies.

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

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