Solved

concatenating two columns data excel

Posted on 2011-09-22
7
222 Views
Last Modified: 2012-05-12
Hi,
I have an Excel sheet, in that I have a column header and it has merged of 3 columns, we can consider those 3 columns as sub-headers for the main column header. Now I want to make these 3 columns into one column without loosing their values. If there is no data/values in the beside column thats not a problem at all, but if there is any data/value in beside column I want to concatenate them with a small dash symbol. How can i do this? Please help me.
Thanks in advance.
0
Comment
Question by:CPSRI
[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
  • 3
  • 2
  • 2
7 Comments
 
LVL 24

Expert Comment

by:Brian B
ID: 36582923
To concatenate two pieces of text, you use the & operator.

So, =A1&B1 would display the contents of those cells together.

If you wanted to concatenate the contents of two cells with a - between them, it would look like this:

=A1&" - "&B1

Does that sound like what you are looking for?
0
 

Author Comment

by:CPSRI
ID: 36583142
No, its not what i am looking for, i want to make them one and delete those 3 columns, and it should check whether its empty, if it has some contents then it should add a '-' symbol, if there is no content it should leave blank.
0
 
LVL 27

Accepted Solution

by:
Glenn Ray earned 500 total points
ID: 36583243
To concatenate values in three columns - say columns A, B, and C,
AND display that in column D,
AND include a hyphen only when there are values in adjacent columns,

then you would insert the following formula in the first applicable row (for example, row 2)
=IF(A2<>"",A2&IF(B2<>"","-",""),"")&IF(B2<>"",B2&IF(C2<>"","-","")&C2,IF(C2<>"",IF(A2<>"","-","")&C2,""))

This will prevent a hyphen from being inserted as a delimiter if any cell has no value.  This works for all eight possible combinations of blanks/values in three columns.  (I'm sure there's a more elegant solution, but this works.)
===============================================
To complete the action as you described in your second comment, copy all the cells containing the formula (column D in this example), paste special: values, then delete the first three columns.

-Glenn
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

Author Comment

by:CPSRI
ID: 36583431
wow.it worked out for me, thank you so much, and one more thing i need. what if i have to concatenate 2 or 4 columns?
0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 36583541
For two columns (assuming A & B):
=IF(A2<>"",A2&IF(B2<>"","-",""),"")&IF(B2<>"",B2,"")

For four columns (assuming A,B,C,D), deep breath now:

=IF(A17<>"",A17&IF(B17<>"","-",""),"")&IF(B17<>"",B17&IF(C17<>"","-","")&C17,IF(C17<>"",IF(A17<>"","-","")&C17,""))&IF(D17<>"",IF(OR(A17<>"",B17<>"",C17<>""),"-"&D17,D17),"")

-Glenn
0
 
LVL 24

Expert Comment

by:Brian B
ID: 36591026
Sorry I misunderstood. You said you wanted to delete the columns. A formula can't delete columns. That would require a macro. Hopefully using the ampersand operator helped contribute to the solution.
0
 

Author Closing Comment

by:CPSRI
ID: 36598004
thank you
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

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.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

726 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