Merging/deleting duplicate cell values

0

I have an issue with merging cells with same values. I receive excel files that vary in columns and rows amount so I can't use macros set for stiff amount of rows or columns. What I have is like this excel before merging

The first row is of course header row that have filter in them. What I want to have should be like this

excel after merging

So I can still sort things by all columns (so cool bikes will still show me 4 rows) Is there a macro or a script that can do that and not get not responsive from the size of sheet (few thousand rows sometimes) AND will not need to be manually change and set up for every sheet?

Thanks in advance for any help.

SZCZERZO KŁY

Posted 2016-09-08T11:01:31.710

Reputation: 101

Yup, I can. The first one from Kutools return " Application-defined or object-defined error" the second one needs the range to be set for only one column and then still require to select array by hand. – SZCZERZO KŁY – 2016-09-08T11:51:15.453

You won't be able to sort after merging just the tagline cells. And the merging process will destroy data in all the merged cells except for the top cell in the merged group. – Ron Rosenfeld – 2016-09-08T15:13:45.210

Answers

1

If this is a display issue, you can merely use Conditional Formatting.

The Rule would be:

=$C1=$C2

and the Format would be under Number Format the custom format of: ;;;

And, no matter by what column you sorted, the tagline would also apply to the blank appearing rows above it, just as in your example.

This sorting and application of Conditional Formatting could be done in a macro, if you like.

However, you would have to sort by tagline last in order to keep all bikes with the same tagline grouped together.

enter image description here

enter image description here

Ron Rosenfeld

Posted 2016-09-08T11:01:31.710

Reputation: 3 333

0

This Macro should work:

Public Sub merger()
    Application.DisplayAlerts = False
    Dim wkb As Workbook
    Dim wks As Worksheet
    Set wkb = ThisWorkbook
    Set wks = wkb.Sheets("Sheet1")
    firstrow = 2
    lastcolumn = "Z"
    columnsortkey = "C"
    columnmerge = 3
    Columns("A:" & lastcolumn).Sort key1:=Range(columnsortkey & ":" & columnsortkey), Header:=xlYes
    theEnd = False
    thisrow = firstrow
    found = False
    Count = 0
    While theEnd = False
        firstCell = wks.Cells(thisrow, columnmerge)
        nextCell = wks.Cells(thisrow + 1, columnmerge)
        If firstCell = nextCell Then
            If found = False Then
                found = True
                mergerfirst = thisrow
                Count = Count + 1
            Else
                Count = Count + 1
            End If
        Else
            If found = True Then
                Range(Cells(mergerfirst, columnmerge), Cells(mergerfirst + Count, columnmerge)).Merge
                found = False
                Count = 0
            End If
        End If
        thisrow = thisrow + 1
        If firstCell = "" Then theEnd = True
    Wend
    Application.DisplayAlerts = True
End Sub

To make it work you have to open VBA/Macros with ALT+ F11, then under ThisWorkbook insert a new module and paste the code.

jcbermu

Posted 2016-09-08T11:01:31.710

Reputation: 15 868

Thanks for the quick answer. When I try to use the code I get "application defined or object defined error" in the 11 line. I've tried to put dot in key1:=.Range but then I get "invalid or unqualified reference" – SZCZERZO KŁY – 2016-09-08T13:32:39.087

@SZCZERZOKŁY Change the line to Columns("A:" & lastcolumn).Sort key1:=Range("C:C"), Header:=xlYes. It will sort the sheet (columns A to Z) using as key column C. In case it doesn't work, sort manually and add an apostrophe to the line to comment it. – jcbermu – 2016-09-08T13:49:20.597