?
Solved

Merge cells if equal

Posted on 2013-12-02
8
Medium Priority
?
391 Views
Last Modified: 2013-12-02
Hi,
Is it possible to write code or enter a formula that would look down column A and merge the cells that were equal? (there are no empty cells)
0
Comment
Question by:Stephen Byrom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 23

Expert Comment

by:NBVC
ID: 39690951
Do you mean you want to end up with Unique Values Only?

If so,try selecting the column of values and go to Data|Remove Duplicates and click Ok.
0
 
LVL 5

Expert Comment

by:jboddy
ID: 39690995
Can you clarify what you mean by "merge"?
0
 
LVL 1

Author Comment

by:Stephen Byrom
ID: 39691006
Thanks for the pointer, but that contracts the range.
I also tried it using vba with
ActiveSheet.Range("A4:A500").RemoveDuplicates
but that did the same.
I just wanted to clear the cells that were the same. It would be an added bonus if after removing the duplicates the cells could then be merged.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:Stephen Byrom
ID: 39691025
by merge I mean that if for example cells a4 to a10 are the same then a4 to a10 would be merged then continue on down to A500 and merging duplicate cells.
a4 to a10 may be the same so merge, a11 to a26 may be the same so merge, etc.
Sorry I am about to embark on a new workbook and the idea came to me to try this.
column A would have numbers lots of them would be the same as they are populated from input from a userform. Columns B through I would also be populated through that form but all the data would be different so I wanted to keep those rows and just merge column A.
0
 
LVL 23

Assisted Solution

by:NBVC
NBVC earned 200 total points
ID: 39691044
You can use Conditional formatting so that the duplicates are coloured as per the background (i.e. white font) so that they are not visible.  This is better than merging cells as that is not recommended, especially if you are going to be referencing them with formulas.

To use conditional formatting, select the range, say A4:A500, then go to Home|Conditonal formatting, then select "use a formula to determine which cells to format", then enter formula:

=COUNTIF($A$4:$A4,$A4)>1

then click Format and choose Font tab to change font to white.

Click Ok and again to finish.
0
 

Assisted Solution

by:Krukanens
Krukanens earned 600 total points
ID: 39691049
'Try this one:

Sub Merge()

    Dim sPreviousField As String
    Dim i As Integer
   
    i = 1
    While Not IsEmpty(Range("A" & i).Value)
       
        If i <> 1 And Range("A" & i).Value = sPreviousField Then
            Application.DisplayAlerts = False
            Range("A" & (i - 1) & ":A" & i).Merge
            Application.DisplayAlerts = True
        Else
            sPreviousField = Range("A" & i).Value
        End If
       
        i = i + 1
    Wend
   
End Sub
0
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 1200 total points
ID: 39691057
Try this

Sub mergesame()
Dim srw As Long
Dim erw As Long
    Application.DisplayAlerts = False
    srw = 1
    Do While Cells(srw, 1) <> ""
        erw = srw
        Do While Cells(srw, 1) = Cells(erw, 1)
            erw = erw + 1
        Loop
        erw = erw - 1
        Range(Cells(srw, 1), Cells(erw, 1)).Merge
        srw = erw + 1
    Loop
    Application.DisplayAlerts = True
End Sub
0
 
LVL 1

Author Closing Comment

by:Stephen Byrom
ID: 39691097
Wow!
Thanks for all the positive solutions.
They all do the trick but ssaqibh gets the lion's share as it executes really quick.

Thanks to all for your time
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question