Skip to main content

How to auto number merged cells in Excel?

How could we fill series numbers into a list of different size merged cells in Excel? First in our mind is to drag the Autofill handle to fill the merged cells, but, in this case, we will get the following warning message, and can’t fill the merged cells.

doc-fill-merged-cells-1

Since the fill handle does not support the merged cells, here, I can talk about some other tricks for solving this problem.

Auto number / fill merged cells with VBA code


arrow blue right bubble Auto number / fill merged cells with VBA code

The following VBA code can help you to number the selected merged cells quickly. Please do as follows:

1. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications window.

2. Click Insert > Module, and paste the following code in the Module Window.

VBA code: Auto number merged cells

Sub NumberCellsAndMergedCells()
	'Update 20141028
	Dim Rng As Range
	Dim WorkRng As Range
	On Error Resume Next
	xTitleId = "KutoolsforExcel"
	Set WorkRng = Application.Selection
	Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type: = 8)
	Set WorkRng = WorkRng.Columns(1)
	xIndex = 1
	Set Rng = WorkRng.Range("A1")
	Do While Not Intersect(Rng, WorkRng) Is Nothing
		Rng.Value = xIndex
		xIndex = xIndex + 1
		Set Rng = Rng.MergeArea.Offset(1)
	Loop
End Sub

3. Then press F5 key to run this code, and a prompt box will pop out to let you select the merged cells you want to fill, see screenshot:

doc-fill-merged-cells-1

4. After selecting the merged cells, and click OK, now, your selected merged cells have been filled with sequential numbers, see screenshot:

doc-fill-merged-cells-1


Related articles:

How to auto number or renumber after filter in Excel?

How to quickly merge adjacent rows with same data in Excel?

How to unmerge cells and fill with duplicate values in Excel?

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...

Description


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!

 

Comments (10)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Thank you!! :)
This comment was minimized by the moderator on the site
Cuando se generan celdas combinadas de diferentes tamaños, y que queremos numerar, podemos seleccionarlas y vaciar el contenido... en seguida con la siguiente fórmula : =IF(Q7="",(COUNTIF($Q$7:Q7,"")),SUBSTITUTE("TRUE","TRUE","")) esta detectará que no hay nada y en la casilla combinada pondrá un consecutivo iniciando con el 1- No importa el tamaño de la celda combinada, solo pondrá el numero al principio de la celda combinada.
This comment was minimized by the moderator on the site
Hi,

How to convert a cell with

Apple, Lemon, Water, Soda, Cap, Bat

into

1. Apple, 2. Lemon, 3. Water, 4. Cap, 5. Bat
This comment was minimized by the moderator on the site
Is there a way to exclude a merged cell that has text in it? This script works perfectly but I'm traversing a document that includes several horizontally merged cells that are made into title bars and I want to skip over/exclude those. Any help would be greatly appreciated!
This comment was minimized by the moderator on the site
This code is working perfectly.


Sub NumberCellsAndMergedCells()
'Update 20141028
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type: = 8)
Set WorkRng = WorkRng.Columns(1)
xIndex = 1
Set Rng = WorkRng.Range("A1")
Do While Not Intersect(Rng, WorkRng) Is Nothing
Rng.Value = xIndex
xIndex = xIndex + 1
Set Rng = Rng.MergeArea.Offset(1)
Loop
End Sub


BUT i want it to select range automatically instead of Set WorkRng = Application.Selection.
Please help.
This comment was minimized by the moderator on the site
I purchased the Kutools so it would help me auto increment my invoice numbering but I am not seeing that feature in the add-in on the Excel tool bar. Maybe I'm not looking for the correct name but I am not finding how to insert this into my invoice template. Any out there
This comment was minimized by the moderator on the site
Hi, was wondering if there is anyway to alter the code where the range value will increase by one e.g. I am trying to use this for invoices and the number should go from NR000026489 to NR000026490, but using the code above with the modification given to JYOTHI it would increase from NR000026489 to NR0000264810. Any help would be greatly appreciated as I've spent ages trying different things but am not advanced enough in VB. Thanks very much :)
This comment was minimized by the moderator on the site
Modify: Do While Not Intersect(Rng, WorkRng) Is Nothing a = xIndex Rng.Value = "Tc_" & a xIndex = xIndex + 1 Set Rng = Rng.MergeArea.Offset(1) Loop
This comment was minimized by the moderator on the site
It is very helpful. but I need one solution, suppose I want to fill series into merged cells but the content of merged cell have data like TC_01, Is it possible to fill next merged cells like TC_02, TC_03etc.. If its possible it helps me a lot. Thanks in advance.
This comment was minimized by the moderator on the site
This was really helpful and solved my problem immediately, thank you very much!
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations