Solved

concatenating two columns data excel

Posted on 2011-09-22
7
217 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
  • 3
  • 2
  • 2
7 Comments
 
LVL 23

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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 23

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

919 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now