Merging Multiple Cells

rdmit141

New Member
Joined
Jan 24, 2016
Messages
1
Hi,

I am working on huge data in which I have Device Names in Column B and its Connecting interfaces in Column C.
Column B has single entry against multiple entries in Column C. I want to merge Cells in Column B w.r.t column C cells.automatically. Number Cells/rows are unequal in column C for each entry against Column B.

I know how to do it manually, but data is huge it will take ages to do that way. I am looking for a way in which it can be merged. It should automatically detect next cell in which data is present minus 1 and merge above all cells.

e.g. in below case Cells from Router 1 (Cell B2) to Router 2{(cell B5)-1}i.e B4 should get merge automatically and merging FROM B5 TO B7, B9 to B14 should happen and so on.

Query 2. how give serial number to merged cells, as the number rows are different, Sr.No are not getting assigned automatically.

Query 3. If I Filter Device "Router 1" I am Getting Output for only one row (1) in column B. I should get output with all entries in Column B

Please share a solution how can I get things done with less headache.


[TABLE="width: 50"]
<tbody>[TR]
[TD="align: center"][/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Sr No.[/TD]
[TD]Device[/TD]
[TD]Interface[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]1[/TD]
[TD]Router1[/TD]
[TD]Gig0[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]2[/TD]
[TD][/TD]
[TD]Gig1[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]3[/TD]
[TD][/TD]
[TD]Gig2[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]4[/TD]
[TD][/TD]
[TD]Gig3[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]5[/TD]
[TD]Router2[/TD]
[TD]Gig0[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]6[/TD]
[TD][/TD]
[TD]Gig1[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]7[/TD]
[TD][/TD]
[TD]Gig2[/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]8[/TD]
[TD]Router 3[/TD]
[TD]Gig0[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD][/TD]
[TD][/TD]
[TD]Gig1[/TD]
[/TR]
[TR]
[TD]11[/TD]
[TD][/TD]
[TD][/TD]
[TD]Gig2[/TD]
[/TR]
[TR]
[TD]12[/TD]
[TD][/TD]
[TD][/TD]
[TD]Gig3[/TD]
[/TR]
[TR]
[TD]13[/TD]
[TD][/TD]
[TD][/TD]
[TD]Gig4[/TD]
[/TR]
[TR]
[TD]14[/TD]
[TD][/TD]
[TD][/TD]
[TD]Gig5[/TD]
[/TR]
[TR]
[TD]15[/TD]
[TD][/TD]
[TD]Router 4[/TD]
[TD]Gig0[/TD]
[/TR]
</tbody>[/TABLE]


Regards,
Rohit
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
rdmit141,

Welcome to the MrExcel forum.

1. What version of Excel, and, Windows are you using?

2. Are you using a PC or a Mac?


You have not displayed what the results should look like.

If I understand you correctly, here is a macro solution for you to consider.

Sample raw data:


Excel 2007
ABC
1Sr No.DeviceInterface
21Router1Gig0
32Gig1
43Gig2
54Gig3
65Router2Gig0
76Gig1
87Gig2
98Router 3Gig0
10Gig1
11Gig2
12Gig3
13Gig4
14Gig5
15Router 4Gig0
16
Sheet1


And, after the macro:


Excel 2007
ABC
1Sr No.DeviceInterface
21Router1Gig0
32Router1Gig1
43Router1Gig2
54Router1Gig3
65Router2Gig0
76Router2Gig1
87Router2Gig2
98Router 3Gig0
109Router 3Gig1
1110Router 3Gig2
1211Router 3Gig3
1312Router 3Gig4
1413Router 3Gig5
1514Router 4Gig0
16
Sheet1


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Sub rdmit141()
' hiker95, 01/24/2016, ME916480
Dim lr As Long, lra As Long
Application.ScreenUpdating = False
lr = Columns("A:C").Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
lra = Cells(Rows.Count, "A").End(xlUp).Row
On Error Resume Next
With Range("B1:B" & lr)
  .SpecialCells(xlCellTypeBlanks).Formula = "=R[-1]C"
  .Value = .Value
End With
Err.Clear
On Error Resume Next
With Range("A" & lra + 1 & ":A" & lr)
  .SpecialCells(xlCellTypeBlanks).Formula = "=R[-1]C+1"
  .Value = .Value
End With
Err.Clear
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm, and, answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.

Then run the rdmit141 macro.
 
Upvote 0

Forum statistics

Threads
1,222,833
Messages
6,168,523
Members
452,194
Latest member
Lowie27

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