Merge based on cell content macro

doriannjeshi

Active Member
Joined
Apr 5, 2015
Messages
338
Office Version
  1. 365
Platform
  1. Windows
Hi,
I have this macro that merges column B cells, if column A cells are the same
Is possible to 1)change the range to be until the end of data in column A (not set like this Range("A2:A111150")
2)The merging to not include row 1 , as right now it merges the header too

Dim cellsA As Range
Dim i As Long
i = 1
For Each cellsA In ActiveSheet.Range("A2:A111150") 'expand range to your needs
If cellsA.Value <> cellsA.Offset(1, 0).Value Then
Range("B" & i & ":B" & cellsA.Row).Merge
i = cellsA.Row + 1
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
this is what it does:

Book1
AB
1juneheader
2april
3april
4april
5march
6october
7november
8may
9january
10february
11february
12february
13june
14april
15
16RESULTS
17juneheader
18april
19april
20april
21march
22october
23november
24may
25january
26february
27february
28february
29june
30april
Sheet1
 
Upvote 0
I know what it does, the question is what do you want it to do as your description doesn't match the code.
 
Upvote 0
Since it messes the header and the range is too long , I want to:
1)change the range to be until the end of data in column A (not set like this Range("A2:A111150")
2)The merging to not include row 1 , as right now it merges the header too

the headers are always in row 1
 
Upvote 0
Try

VBA Code:
Sub xxxx()
    Dim cellsA As Range

    With Application
        .DisplayAlerts = False
        .ScreenUpdating = False
    End With

    For Each cellsA In Range("A3:A" & Range("A" & Rows.Count).End(xlUp).Row) 'expand range to your needs
        If cellsA.Value = cellsA.Offset(-1, 0).Value Then cellsA.Offset(-1, 1).Resize(2).Merge
    Next

    Application.DisplayAlerts = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,114
Members
453,021
Latest member
Justyna P

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