Help please - Graduation Project - Merge ALL cells with same value in a sheet. [rows AND columns]

iJihad

New Member
Joined
May 11, 2014
Messages
3
Hello there,

We are doing a graduation project on an international airport, consist of scheduling flights on check-in counters automatically.

long story short, we ended up with an excel sheet like this:

Screen_Shot_2014-05-11_at_4.png




Were y-axis are the check-in counters and x-axis is the timeline horizon (cell per 5-minutes)

I will do a VLOOKUP, to change each flight number to it's ID from an other sheet.

But the problem is that i want to AUTO-MERGE all cells with same value, because they represent one flight! and if i shortened the column width i can't see anything.

I want it to be like this: (i've done this manually, and it's VERY time consuming with errors because we have to do it for all days.)

Screen_Shot_2014-05-11_at_46FDQO.png




I googled for days, i only found Visual basic commands i guess? that only merge same rows. and they were poorly made. beside that it didn't work properly.

Could anyone please help me with a method to do it automatically?


EXCEL 2013


Thanks a lot!
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
NOTE: i only posted the question on excelforum website here, i wouldn't do it normally, but we are late for deadline :(. sorry!


Also, what i'm looking for is merging all cells with same value if they are vertically or horizontally adjacent.

OR maybe merging all cells in a certain range if they are same value. Because in the whole sheet, no cells are with same value unless they are adjacent.
 
Last edited:
Upvote 0
Like this :
Code:
Sub MergeCells()    Dim rg As Range, rgF As Range, c As Range
    Dim i As Integer
    
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    
    Set rg = Range("A1:Z30")        'DEFINE YOUR RANGE HERE
    
    On Error Resume Next
    For i = 1 To 50                 'VALUES YOUR ARE LOOKING FOR AND WANT TO MERGE
        For Each c In rg
            If c.Value = i Then
                If rgF Is Nothing Then
                    Set rgF = c
                Else
                    Set rgF = Union(rgF, c)
                End If
            End If
        Next c
        rgF.Merge
        Set rgF = Nothing
    Next i
    On Error GoTo 0
    
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
    
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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