Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 553
Default Conditional Concatination

Hi every1

I have NINE columns showing different levels. An example:

Level 1 Level 2 Level 3 Level 4
A 1 a
A 2 a i
A 2 a ii
A 2 b i
B 1
B 2 a
B 2 b
C 1
C 2
D
E 1

Now what sort of SHORT formula should be placed in the column E (actually
10th column in the original data) which would concatinate the levels' columns
resulting as follows, without using the IF() condition for placing "-"
(hyphens):

A - 1 - a
A - 2 - a - i
A - 2 - a - ii
A - 2 - b - i
B - 1
B - 2 - a
B - 2 - b
C - 1
C - 2
D
E - 1

--
Best Regards,
FARAZ A. QURESHI
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,593
Default Conditional Concatination

A simple UDF

Public Function MyJoin(ParamArray rng())
Dim i As Long
Dim cell As Range
Dim tmp As String

For i = LBound(rng) To UBound(rng)

For Each cell In rng(i)

If cell.Value < "" Then

tmp = tmp & "-" & cell.Value
End If
Next cell
Next i
If Len(tmp) 0 Then tmp = Right(tmp, Len(tmp) - 1)
MyJoin = tmp
End Function


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"FARAZ QURESHI" wrote in message
...
Hi every1

I have NINE columns showing different levels. An example:

Level 1 Level 2 Level 3 Level 4
A 1 a
A 2 a i
A 2 a ii
A 2 b i
B 1
B 2 a
B 2 b
C 1
C 2
D
E 1

Now what sort of SHORT formula should be placed in the column E (actually
10th column in the original data) which would concatinate the levels'
columns
resulting as follows, without using the IF() condition for placing "-"
(hyphens):

A - 1 - a
A - 2 - a - i
A - 2 - a - ii
A - 2 - b - i
B - 1
B - 2 - a
B - 2 - b
C - 1
C - 2
D
E - 1

--
Best Regards,
FARAZ A. QURESHI



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,856
Default Conditional Concatination

Put this in E2:

=A2&IF(B2<""," - "&B2,"")&IF(C2<""," - "&C2,"")&IF(D2<""," -
"&D2,"")

then copy down.

Not sure why you want to avoid using IF.

Hope this helps.

Pete

On Jan 23, 11:37*am, FARAZ QURESHI
wrote:
Hi every1

I have NINE columns showing different levels. An example:

Level 1 * * Level 2 * * Level 3 * * Level 4
A * * * * * * *1 * * * * * * a
A * * * * * * *2 * * * * * * a * * * * * * *i
A * * * * * * *2 * * * * * * a * * * * * * *ii
A * * * * * * *2 * * * * * * b * * * * * * *i
B * * * * * * *1
B * * * * * * *2 * * * * * * a
B * * * * * * *2 * * * * * * b
C * * * * * * *1
C * * * * * * *2
D
E * * * * * * *1

Now what sort of SHORT formula should be placed in the column E (actually
10th column in the original data) which would concatinate the levels' columns
resulting as follows, without using the IF() condition for placing "-"
(hyphens):

A - 1 - a
A - 2 - a - i
A - 2 - a - ii
A - 2 - b - i
B - 1
B - 2 - a
B - 2 - b
C - 1
C - 2
D
E - 1

--
Best Regards,
FARAZ A. QURESHI


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 99
Default Conditional Concatination

Hi, Or a shortish formula, put in E2 and copied down:

=LEFT(A2&"-"&B2&"-"&C2&"-"&D2,2*COUNTA(A2:D2)-1)

Dave



"Bob Phillips" wrote:

A simple UDF

Public Function MyJoin(ParamArray rng())
Dim i As Long
Dim cell As Range
Dim tmp As String

For i = LBound(rng) To UBound(rng)

For Each cell In rng(i)

If cell.Value < "" Then

tmp = tmp & "-" & cell.Value
End If
Next cell
Next i
If Len(tmp) 0 Then tmp = Right(tmp, Len(tmp) - 1)
MyJoin = tmp
End Function


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"FARAZ QURESHI" wrote in message
...
Hi every1

I have NINE columns showing different levels. An example:

Level 1 Level 2 Level 3 Level 4
A 1 a
A 2 a i
A 2 a ii
A 2 b i
B 1
B 2 a
B 2 b
C 1
C 2
D
E 1

Now what sort of SHORT formula should be placed in the column E (actually
10th column in the original data) which would concatinate the levels'
columns
resulting as follows, without using the IF() condition for placing "-"
(hyphens):

A - 1 - a
A - 2 - a - i
A - 2 - a - ii
A - 2 - b - i
B - 1
B - 2 - a
B - 2 - b
C - 1
C - 2
D
E - 1

--
Best Regards,
FARAZ A. QURESHI




  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,856
Default Conditional Concatination

Hi Dave,

this doesn't work for the third example.

Pete

On Jan 23, 12:56*pm, Dave Curtis
wrote:
Hi, Or a shortish formula, put in E2 and copied down:

=LEFT(A2&"-"&B2&"-"&C2&"-"&D2,2*COUNTA(A2:D2)-1)

Dave




  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 99
Default Conditional Concatination

Well spotted, Pete,

Here's a revised attempt

=LEFT(A2&"-"&B2&"-"&C2&"-"&D2,LEN(A2)+LEN(B2)+LEN(C2)+LEN(D2)+COUNTA(A2 :D2)-1)

Dave


"Pete_UK" wrote:

Hi Dave,

this doesn't work for the third example.

Pete

On Jan 23, 12:56 pm, Dave Curtis
wrote:
Hi, Or a shortish formula, put in E2 and copied down:

=LEFT(A2&"-"&B2&"-"&C2&"-"&D2,2*COUNTA(A2:D2)-1)

Dave



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with concatination result. Last digit change to 0 DavCan Excel Worksheet Functions 1 August 24th 07 11:48 PM
Conditional Rank (or rather, Conditional Range) [email protected] Excel Worksheet Functions 6 April 16th 07 06:15 PM
How set a format on one of more strings in a concatination Steen Excel Discussion (Misc queries) 6 October 29th 06 04:34 PM
Conditional Formatting that will display conditional data BrainFart Excel Worksheet Functions 1 September 13th 05 05:45 PM
Excal Concatination of cells that are not empty orourksj Excel Worksheet Functions 5 January 20th 05 09:51 PM


All times are GMT +1. The time now is 09:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"