PC Review


Reply
Thread Tools Rate Thread

Combining Text based on Values

 
 
cardan
Guest
Posts: n/a
 
      22nd Sep 2011
Hi,
I am working with text and trying to create a string of text based on
values within a certain range and I am having trouble combining it.

In column A (A1:A6), I have products, say A, B, C, D, E, F. In column
B (B1:B6) are corresponding numbers that equal the number of that
product. These numbers are either equal to or greater than zero and
are always changing. Sometimes only one product will be greater than
zero, or it can be any combination of the products; for example, A, C,
& F will have values greater than zero, or just B & C, or just “E”
will be the only one with values greater than zero.

What I would like to do is write a formula that will combine and
return the product name(s) based on the values in column B. For
example, if product A is the only one greater than zero, then have it
equal “A”, if say A,C,& F have values, have it return “A/C/F” or “B/C”
etc… The slashes would be an ideal separator but not necessary.
I have tried concatenate but had no luck with combining formulas or
accounting for the numerous variations and realized very quickly, I
have no clue where to start. Any feedback would be most helpful.
Thanks
 
Reply With Quote
 
 
 
 
Gord
Guest
Posts: n/a
 
      22nd Sep 2011
Function concat(CellBlock As Range) As String
Dim cell As Range
Dim sbuf As String
For Each cell In CellBlock
If cell.Value > 0 Then sbuf = sbuf & cell.Offset(0, -1).Text & "/"
Next
concat = Left(sbuf, Len(sbuf) - 1)
End Function

=concat(B1:B6)


Gord Dibben Microsoft Excel MVP

On Thu, 22 Sep 2011 08:37:57 -0700 (PDT), cardan
<(E-Mail Removed)> wrote:

>Hi,
>I am working with text and trying to create a string of text based on
>values within a certain range and I am having trouble combining it.
>
>In column A (A1:A6), I have products, say A, B, C, D, E, F. In column
>B (B1:B6) are corresponding numbers that equal the number of that
>product. These numbers are either equal to or greater than zero and
>are always changing. Sometimes only one product will be greater than
>zero, or it can be any combination of the products; for example, A, C,
>& F will have values greater than zero, or just B & C, or just “E”
>will be the only one with values greater than zero.
>
>What I would like to do is write a formula that will combine and
>return the product name(s) based on the values in column B. For
>example, if product A is the only one greater than zero, then have it
>equal “A”, if say A,C,& F have values, have it return “A/C/F” or “B/C”
>etc… The slashes would be an ideal separator but not necessary.
>I have tried concatenate but had no luck with combining formulas or
>accounting for the numerous variations and realized very quickly, I
>have no clue where to start. Any feedback would be most helpful.
>Thanks

 
Reply With Quote
 
cardan
Guest
Posts: n/a
 
      22nd Sep 2011
On Sep 22, 9:57*am, Gord <phnor...@shaw.ca> wrote:
> Function concat(CellBlock As Range) As String
> Dim cell As Range
> Dim sbuf As String
> * * For Each cell In CellBlock
> * * If cell.Value > 0 Then sbuf = sbuf & cell.Offset(0, -1).Text & "/"
> * * Next
> * * concat = Left(sbuf, Len(sbuf) - 1)
> End Function
>
> =concat(B1:B6)
>
> Gord Dibben * *Microsoft Excel MVP
>
> On Thu, 22 Sep 2011 08:37:57 -0700 (PDT), cardan
>
>
>
> <carlsondan...@gmail.com> wrote:
> >Hi,
> >I am working with text and trying to create a string of text based on
> >values within a certain range and I am having *trouble combining it.

>
> >In column A (A1:A6), I have products, say A, B, C, D, E, F. *In column
> >B (B1:B6) are corresponding numbers that equal the number of that
> >product. *These numbers are either equal to or greater than zero and
> >are always changing. *Sometimes only one product will be greater than
> >zero, or it can be any combination of the products; for example, A, C,
> >& F will have values greater than zero, or just B & C, or just E
> >will be the only one with values greater than zero.

>
> >What I would like to do is write a formula that will combine and
> >return the product name(s) based on the values in column B. *For
> >example, if product A is the only one greater than zero, then have it
> >equal A , if say A,C,& F have values, have it return A/C/F or B/C
> >etc *The slashes would be an ideal separator but not necessary.
> >I have tried concatenate but had no luck with combining formulas or
> >accounting for the numerous variations and realized very quickly, I
> >have no clue where to start. *Any feedback would be most helpful.
> >Thanks- Hide quoted text -

>
> - Show quoted text -


Hi Gord, Thank you for the quick reply. Would there be a way to do
this with just formulas? My VBA skills are not that great and I am
not familiar (and confident) with inputting code. Thanks again.
 
Reply With Quote
 
Gord
Guest
Posts: n/a
 
      22nd Sep 2011
You posted in programming group so assumed you could handle
programming.

I can't think of any worksheet formula solution at the moment. I'm
sure someone will jump in with a worksheet function solution for you.

In the meantime this might be a good time to start to learn VBA which
is a powerful adjunct to Excel and would make your Excel life so much
easier IMO.

What I posted was a User Defined Function.

To set it up.........................

With your workbook open hit Alt + F11 to open the Visual Basic Editor.

CTRL + r to open the Project Explorer.

Select your workbook/project and right-click>insert>module

Paste the UDF into that module. Save the workbook. Alt + q to return
to Excel.

In a cell enter =concat(B1:B6)


Gord

On Thu, 22 Sep 2011 10:35:49 -0700 (PDT), cardan
<(E-Mail Removed)> wrote:

>Hi Gord, Thank you for the quick reply. Would there be a way to do
>this with just formulas? My VBA skills are not that great and I am
>not familiar (and confident) with inputting code. Thanks again.

 
Reply With Quote
 
cardan
Guest
Posts: n/a
 
      22nd Sep 2011
On Sep 22, 10:55*am, Gord <phnor...@shaw.ca> wrote:
> You posted in programming group so assumed you could handle
> programming.
>
> I can't think of any worksheet formula solution at the moment. *I'm
> sure someone will jump in with a worksheet function solution for you.
>
> In the meantime this might be a good time to start to learn VBA which
> is a powerful adjunct to Excel and would make your Excel life so much
> easier IMO.
>
> What I posted was a User Defined Function.
>
> To set it up.........................
>
> With your workbook open hit Alt + F11 to open the Visual Basic Editor.
>
> CTRL + r to open the Project Explorer.
>
> Select your workbook/project and right-click>insert>module
>
> Paste the UDF into that module. *Save the workbook. *Alt + q to return
> to Excel.
>
> In a cell enter *=concat(B1:B6)
>
> Gord
>
> On Thu, 22 Sep 2011 10:35:49 -0700 (PDT), cardan
>
>
>
> <carlsondan...@gmail.com> wrote:
> >Hi Gord, *Thank you for the quick reply. *Would there be a way to do
> >this with just formulas? *My VBA skills are not that great and I am
> >not familiar (and confident) with inputting code. *Thanks again.- Hidequoted text -

>
> - Show quoted text -


Hi Gord, Thank you for the input. I usually do some complex formula
writing and found I get the best reponses here, so I usually asked my
questions here under the programming group. Also sometimes I have to
share the models and sometimes others don't know anything about macros
(less than I do) so I will stay away from them (and sometimes arrays
too).

I followed your instructions and it works great. One question I do
have, is if I wanted to copy that formula over to other columns, how
can I make it so that it will reference the names in Column A, but
adjust based on the values within another column. It is my fault for
not being specific enough. I figured I would keep my question as
simple as possible since I can always copy a formula easily. Thank
you again for your assistance.
 
Reply With Quote
 
Gord
Guest
Posts: n/a
 
      24th Sep 2011
Sorry for the delay...........hope you're still watching.

Here is a modification that will allow dragging formula across while
keeping column A as reference to names.

Function concat(CellBlock As Range) As String
Dim cell As Range
Dim sbuf As String
For Each cell In CellBlock
If cell.Value > 0 Then sbuf = sbuf & _
Range("A" & cell.Row).Text & "/"
Next
concat = Left(sbuf, Len(sbuf) - 1)
End Function


Gord


On Thu, 22 Sep 2011 11:58:03 -0700 (PDT), cardan
<(E-Mail Removed)> wrote:

>Hi Gord, Thank you for the input. I usually do some complex formula
>writing and found I get the best reponses here, so I usually asked my
>questions here under the programming group. Also sometimes I have to
>share the models and sometimes others don't know anything about macros
>(less than I do) so I will stay away from them (and sometimes arrays
>too).
>
>I followed your instructions and it works great. One question I do
>have, is if I wanted to copy that formula over to other columns, how
>can I make it so that it will reference the names in Column A, but
>adjust based on the values within another column. It is my fault for
>not being specific enough. I figured I would keep my question as
>simple as possible since I can always copy a formula easily. Thank
>you again for your assistance.

 
Reply With Quote
 
cardan
Guest
Posts: n/a
 
      26th Sep 2011
On Sep 24, 11:32*am, Gord <phnor...@shaw.ca> wrote:
> Sorry for the delay...........hope you're still watching.
>
> Here is a modification that will allow dragging formula across while
> keeping column A as reference to names.
>
> Function concat(CellBlock As Range) As String
> Dim cell As Range
> Dim sbuf As String
> * * For Each cell In CellBlock
> * * If cell.Value > 0 Then sbuf = sbuf & _
> * * * * *Range("A" & cell.Row).Text & "/"
> * * Next
> * * concat = Left(sbuf, Len(sbuf) - 1)
> End Function
>
> Gord
>
> On Thu, 22 Sep 2011 11:58:03 -0700 (PDT), cardan
>
>
>
> <carlsondan...@gmail.com> wrote:
> >Hi Gord, Thank you for the input. *I usually do some complex formula
> >writing and found I get the best reponses here, so I usually asked my
> >questions here under the programming group. *Also sometimes I have to
> >share the models and sometimes others don't know anything about macros
> >(less than I do) so I will stay away from them (and sometimes arrays
> >too).

>
> >I followed your instructions and it works great. *One question I do
> >have, is if I wanted to copy that formula over to other columns, how
> >can I make it so that it will reference the names in Column A, but
> >adjust based on the values within another column. *It is my fault for
> >not being specific enough. I figured I would keep my question as
> >simple as possible since I can always copy a formula easily. *Thank
> >you again for your assistance.- Hide quoted text -

>
> - Show quoted text -


Hi Gord, Thank you again for your response. I tried the latest code,
but it does not seem to be taking any differently from the previous
code. I tried to modify it slightly to match my workbook a bit more,
but I it still does the same thing- so it is hard for my novice eyes
see what is happening. Essentially, my names are actually in column D
(D:2024). I am starting my "concat" formula in column E (E7). It
works great in cell E7. but when I copy the formula to F7, it then
returns the values that were are in column E rather than the names in
Column D.

I thought I could change this by renaming the range from "A" to "D",
or possibly changing the -1 in the concat formula but no luck. I am
sure it is an easy fix, I just don't know where to start. Thank you
again for your continued assistance on this! -Dan
 
Reply With Quote
 
GS
Guest
Posts: n/a
 
      26th Sep 2011
cardan explained :
> On Sep 24, 11:32*am, Gord <phnor...@shaw.ca> wrote:
>> Sorry for the delay...........hope you're still watching.
>>
>> Here is a modification that will allow dragging formula across while
>> keeping column A as reference to names.
>>
>> Function concat(CellBlock As Range) As String
>> Dim cell As Range
>> Dim sbuf As String
>> * * For Each cell In CellBlock
>> * * If cell.Value > 0 Then sbuf = sbuf & _
>> * * * * *Range("A" & cell.Row).Text & "/"
>> * * Next
>> * * concat = Left(sbuf, Len(sbuf) - 1)
>> End Function
>>
>> Gord
>>
>> On Thu, 22 Sep 2011 11:58:03 -0700 (PDT), cardan
>>
>>
>>
>> <carlsondan...@gmail.com> wrote:
>>> Hi Gord, Thank you for the input. *I usually do some complex formula
>>> writing and found I get the best reponses here, so I usually asked my
>>> questions here under the programming group. *Also sometimes I have to
>>> share the models and sometimes others don't know anything about macros
>>> (less than I do) so I will stay away from them (and sometimes arrays
>>> too).

>>
>>> I followed your instructions and it works great. *One question I do
>>> have, is if I wanted to copy that formula over to other columns, how
>>> can I make it so that it will reference the names in Column A, but
>>> adjust based on the values within another column. *It is my fault for
>>> not being specific enough. I figured I would keep my question as
>>> simple as possible since I can always copy a formula easily. *Thank
>>> you again for your assistance.- Hide quoted text -

>>
>> - Show quoted text -

>
> Hi Gord, Thank you again for your response. I tried the latest code,
> but it does not seem to be taking any differently from the previous
> code. I tried to modify it slightly to match my workbook a bit more,
> but I it still does the same thing- so it is hard for my novice eyes
> see what is happening. Essentially, my names are actually in column D
> (D:2024). I am starting my "concat" formula in column E (E7). It
> works great in cell E7. but when I copy the formula to F7, it then
> returns the values that were are in column E rather than the names in
> Column D.
>
> I thought I could change this by renaming the range from "A" to "D",
> or possibly changing the -1 in the concat formula but no luck. I am
> sure it is an easy fix, I just don't know where to start. Thank you
> again for your continued assistance on this! -Dan


To reference the column containing names, prefix the column letter with
"$".

So...<snip>

If cell.Value > 0 Then sbuf = sbuf & _
Range("$D") & cell.Row).Text & "/"

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


 
Reply With Quote
 
Gord
Guest
Posts: n/a
 
      27th Sep 2011
Names in D2024............got that.

First formula in E7...........got that.

Which column contains the corresponding numbers that are either equal
to or greater than zero and are always changing?

We built the function based on your original description where you had
a column of names and a column of numbers.

I revised it so you could have a fixed column of names and multiple
contiguous columns of numbers to the right of that names column.

You don't have even one column of numbers, much less two or more.

If you want to send me a copy of your workbook and an explanation feel
free to send to my email.................not the group.

Change phnorton to gorddibb


Gord


On Mon, 26 Sep 2011 12:48:51 -0700 (PDT), cardan
<(E-Mail Removed)> wrote:

>Hi Gord, Thank you again for your response. I tried the latest code,
>but it does not seem to be taking any differently from the previous
>code. I tried to modify it slightly to match my workbook a bit more,
>but I it still does the same thing- so it is hard for my novice eyes
>see what is happening. Essentially, my names are actually in column D
>(D:2024). I am starting my "concat" formula in column E (E7). It
>works great in cell E7. but when I copy the formula to F7, it then
>returns the values that were are in column E rather than the names in
>Column D.
>
>I thought I could change this by renaming the range from "A" to "D",
>or possibly changing the -1 in the concat formula but no luck. I am
>sure it is an easy fix, I just don't know where to start. Thank you
>again for your continued assistance on this! -Dan

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
combining data from 2 sheet into new sheet based on like values Versace77 Microsoft Excel Programming 2 28th Jul 2009 07:01 PM
Combining Text and Date Values =?Utf-8?B?S2F0aGVyaW5lIFI=?= Microsoft Access 2 14th Dec 2005 04:00 PM
Acc97: Combining Values & Text noodnutt Microsoft Access Form Coding 3 1st May 2005 11:05 AM
Merging or combining Text based Fields compunow Microsoft Access Queries 4 25th Oct 2003 09:44 PM
combining text values from multiple fields vwillia2 Microsoft Access Reports 1 6th Aug 2003 05:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:41 PM.