concatenate only non zero values

NapervilleMike

New Member
Joined
Aug 1, 2012
Messages
19
So here is what I have:

Substancequantity
Water98
Sodium.5
Potassium1
Calcium.5
Magnesium0

<tbody>
</tbody>

What I need is a formula that will concatenate only the non-zero's and the substance associated with them. For example this out put should say: Water, 98; Sodium .5; Potassium, 1; Calcium .5

If this seems pointless, the reason I need a methodology because I actually have about 50 substances and there are about 30 "quantity" columns and I would like a nice way to automate this and apply it to other similar applications.

Thanks.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Sorry, I'm an idiot and you are the best.

I know I say this every time I come here for help, but you all are wonderful and make me look like some genius boy wonder at work,
 
Upvote 0
Hi, I'm a new member and excel user. I'm also searching for the same solution, but I want the result line by line.

The sample data

A B

2 Apple

4 Orange

7 Banana

8 Grapes

0 Berry

I want the final result in a cell like ; (combined data with carriage return after each data)

2 Apple
4 Orange
7 Banana
8 Grapes

By concatenating only the non zero cells

Thanx in advance.
Shashi
 
Last edited:
Upvote 0
A B

2 Apple

4 Orange

7 Banana

8 Grapes

0 Berry

I want the final result in a cell like ; (combined data with carriage return after each data)

2 Apple
4 Orange
7 Banana
8 Grapes

By concatenating only the non zero cells
Give this modification to the code I posted earlier in this thread a try...
Code:
Function JoinSubs(SubstanceRange As Range, QualityRange As Range) As String
  Dim X As Long, LastRow As Long, Txt As String
  LastRow = Cells(Rows.Count, SubstanceRange.Column).End(xlUp).Row
  JoinSubs = Join(Application.Transpose(Evaluate("IF(" & QualityRange.Address & "=0,""""," & _
             SubstanceRange.Address & "&"", ""&" & QualityRange.Address & ")")), vbLf)
  Do While InStr(JoinSubs, vbLf & vbLf)
    JoinSubs = Replace(JoinSubs, vbLf & vbLf, vbLf)
  Loop
  JoinSubs = Trim(JoinSubs)
  If Right(JoinSubs, 1) = vbLf Then JoinSubs = Left(JoinSubs, Len(JoinSubs) - 1)
End Function
This is the formula you would put in the cell you wanted the concatenation to appear in...

=JoinSubs(B1:B100,A1:A100)

where you would change both 100's to the row number containing your last row of data (a row number bigger than that will also work). Note that you will have to manually turn on word wrapping (Cell Formatting/Alignment Tab) for the line-by-line display to show up correctly.
 
Upvote 0
Sir,
I'm attaching the file and in this file i've explained how i want the result.
Example.xlsm - Speedy Share - upload your files here
shashi
Sorry, but that website wants to install something called "Tiny DM Manager" on my computer in order to download your file and I will not do that. If you want to email the file to me directly, my email address is....

rick DOT news AT verizon DOT net

Please put the title of this thread in the body of your email so I can relate the file back to this thread more easily.
 
Upvote 0
Sorry, but that website wants to install something called "Tiny DM Manager" on my computer in order to download your file and I will not do that. If you want to email the file to me directly, my email address is....

rick DOT news AT verizon DOT net

Please put the title of this thread in the body of your email so I can relate the file back to this thread more easily.

Sir,
I've emailed the file
Shashi
 
Upvote 0
Sir,
I've emailed the file
For those who did not want to download the file for the same reason I stated in Message #18, here is roughly what it looked like (the column widths did not end up correct in it, Columns E:H should all be the same width and that width should be wide enough to show cell E15 with 4 rows having a number in front of each row)...

ABCDEFGHI
1Sl. No.Work DetailsFinance for April 2014Finance for May 2014Finance for June 2014Finance for July 2014
21Work 120405010
32Work 234622013
43Work 312401013
54Work 41031540
65Work 550202025
76Work 610151025
87Work 73202060
9Color codeStatusAprilMayJuneAugust
10Works Tender Process2302
11Works Started2002
12Works Under Progress2243
13Works Completed1230
14This following is the Result I want
152 Works Tender Process
2 Works Started
2 Works Under Progress
1 Works Completed
3 Works Tender Process
2 Works Under Progress
2 Works Completed
4 Works Under Progress
3 Works Completed
2 Works Tender Process
2 Works Started
3 Works Under Progress
16
17Note : I will get numbers for the months by counting cells having particular color fill
18

<tbody>
</tbody>

Here is the revised UDF that I came up with for it...
Code:
Function ColorCounts(ColorCountRange As Range, StatusRange As Range) As String
  Dim X As Long, LastRow As Long, Txt As String
  LastRow = Cells(Rows.Count, ColorCountRange.Column).End(xlUp).Row
  ColorCounts = Join(Application.Transpose(Evaluate("IF(" & ColorCountRange.Address & "=0,""""," & _
             ColorCountRange.Address & "&"" ""&" & StatusRange.Address & ")")), vbLf)
  Do While InStr(ColorCounts, vbLf & vbLf)
    ColorCounts = Replace(ColorCounts, vbLf & vbLf, vbLf)
  Loop
  If Left(ColorCounts, 1) = vbLf Then ColorCounts = Mid(ColorCounts, 2)
  If Right(ColorCounts, 1) = vbLf Then ColorCounts = Left(ColorCounts, Len(ColorCounts) - 1)
End Function
Once this code is installed in accordance with the directions I gave in Message #5, then put this formula in cell E15 and copy it across to cell H15...

=ColorCounts(E10:E13,$D10:$D13)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,461
Messages
6,124,952
Members
449,198
Latest member
MhammadishaqKhan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top