Solved

concatenating two columns data excel

Posted on 2011-09-22
7
216 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:CPSRI
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
thank you
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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,…
Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
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.

744 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

15 Experts available now in Live!

Get 1:1 Help Now