PC Review


Reply
Thread Tools Rate Thread

to CONCATENATE from the smallest date with at least 2 criteria

 
 
Andri
Guest
Posts: n/a
 
      17th Apr 2010
Dear All,

Here is the sample database.

Date Salesman Region
16-Aug-08 A N
16-Aug-09 B E
16-June-07 C S
15-Aug-07 A S
15-Apr-07 B E
4-Sep-07 D N
4-May-07 E N
6-Sep-07 A N
3-Oct-07 B W
24-Sep-07 E E

i would like to concatenate for Salesman B and Region E(east) in A1, so the
result will be "15-Apr-07,16-Aug-09"... which formula can solve it?

tried SMALL + sumproduct(but...this sum all the date in that arrays).

thank you for your kind attention and help.

respectfully,
andri
 
Reply With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      17th Apr 2010
Andri,

As long as those are properly formatted dates try this ARRAY formula. the
lookup values are in D2 (B) and E2 (E)

=TEXT(MIN(IF(B2:B11=D2,IF(C2:C11=E2,A2:A11))),"dd-mmm-yy")&" ,
"&TEXT(MAX(IF(B2:B11=D2,IF(C2:C11=E2,A2:A11))),"dd-mmm-yy")


This is an array formula which must be entered by pressing CTRL+Shift+Enter
and not just Enter. If you do it correctly then Excel will put curly brackets
around the formula {}. You can't type these yourself. If you edit the formula
you must enter it again with CTRL+Shift+Enter.

--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Andri" wrote:

> Dear All,
>
> Here is the sample database.
>
> Date Salesman Region
> 16-Aug-08 A N
> 16-Aug-09 B E
> 16-June-07 C S
> 15-Aug-07 A S
> 15-Apr-07 B E
> 4-Sep-07 D N
> 4-May-07 E N
> 6-Sep-07 A N
> 3-Oct-07 B W
> 24-Sep-07 E E
>
> i would like to concatenate for Salesman B and Region E(east) in A1, so the
> result will be "15-Apr-07,16-Aug-09"... which formula can solve it?
>
> tried SMALL + sumproduct(but...this sum all the date in that arrays).
>
> thank you for your kind attention and help.
>
> respectfully,
> andri

 
Reply With Quote
 
Andri
Guest
Posts: n/a
 
      17th Apr 2010
Dear Mike,

thank you for your kind and response.

the formula is workable. but it only show for two dates only MIN and MAX.

the required solution, to list down all the date, from the smallest,
increasing date and ended with the Largest date.

so some records might contain several dates (3, 4, 5 or even 6dates).

how to adjust it?

TIA

"Mike H" wrote:

> Andri,
>
> As long as those are properly formatted dates try this ARRAY formula. the
> lookup values are in D2 (B) and E2 (E)
>
> =TEXT(MIN(IF(B2:B11=D2,IF(C2:C11=E2,A2:A11))),"dd-mmm-yy")&" ,
> "&TEXT(MAX(IF(B2:B11=D2,IF(C2:C11=E2,A2:A11))),"dd-mmm-yy")
>
>
> This is an array formula which must be entered by pressing CTRL+Shift+Enter
> and not just Enter. If you do it correctly then Excel will put curly brackets
> around the formula {}. You can't type these yourself. If you edit the formula
> you must enter it again with CTRL+Shift+Enter.
>
> --
> Mike
>
> When competing hypotheses are otherwise equal, adopt the hypothesis that
> introduces the fewest assumptions while still sufficiently answering the
> question.
>
>
> "Andri" wrote:
>
> > Dear All,
> >
> > Here is the sample database.
> >
> > Date Salesman Region
> > 16-Aug-08 A N
> > 16-Aug-09 B E
> > 16-June-07 C S
> > 15-Aug-07 A S
> > 15-Apr-07 B E
> > 4-Sep-07 D N
> > 4-May-07 E N
> > 6-Sep-07 A N
> > 3-Oct-07 B W
> > 24-Sep-07 E E
> >
> > i would like to concatenate for Salesman B and Region E(east) in A1, so the
> > result will be "15-Apr-07,16-Aug-09"... which formula can solve it?
> >
> > tried SMALL + sumproduct(but...this sum all the date in that arrays).
> >
> > thank you for your kind attention and help.
> >
> > respectfully,
> > andri

 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      17th Apr 2010
Hi,

I don't know how to do that with a formula but here's a UDF that does it.
Alt +F11 to open VB editor. Right click "ThisWorkbook' and insert module and
paste the code in

call with

=ConCat(A2:A11,D2,E2)

Where A2:A11 are the dates and D2 & E2 are the 2 lookup values



Function ConCat(rng As Range, rep As String, area As String) As String
Dim R As Long, R1 As Long, x As Long
Application.Volatile
rep = UCase(rep)
area = UCase(area)
For Each c In rng
If UCase(c.Offset(, 1)) = rep And UCase(c.Offset(, 2)) = area Then
MyString = MyString & c.Value & ","
End If
Next
v = Split(MyString, ",")
For R = 0 To UBound(v)
For R1 = R To UBound(v)
If v(R1) < v(R) Then
str1 = v(R)
str2 = v(R1)
v(R) = str2
v(R1) = str1
End If
Next R1
Next R
For x = 1 To UBound(v)
ConCat = ConCat & v(x) & " , "
Next
ConCat = Left(ConCat, (Len(ConCat) - 2))
End Function

--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Andri" wrote:

> Dear Mike,
>
> thank you for your kind and response.
>
> the formula is workable. but it only show for two dates only MIN and MAX.
>
> the required solution, to list down all the date, from the smallest,
> increasing date and ended with the Largest date.
>
> so some records might contain several dates (3, 4, 5 or even 6dates).
>
> how to adjust it?
>
> TIA
>
> "Mike H" wrote:
>
> > Andri,
> >
> > As long as those are properly formatted dates try this ARRAY formula. the
> > lookup values are in D2 (B) and E2 (E)
> >
> > =TEXT(MIN(IF(B2:B11=D2,IF(C2:C11=E2,A2:A11))),"dd-mmm-yy")&" ,
> > "&TEXT(MAX(IF(B2:B11=D2,IF(C2:C11=E2,A2:A11))),"dd-mmm-yy")
> >
> >
> > This is an array formula which must be entered by pressing CTRL+Shift+Enter
> > and not just Enter. If you do it correctly then Excel will put curly brackets
> > around the formula {}. You can't type these yourself. If you edit the formula
> > you must enter it again with CTRL+Shift+Enter.
> >
> > --
> > Mike
> >
> > When competing hypotheses are otherwise equal, adopt the hypothesis that
> > introduces the fewest assumptions while still sufficiently answering the
> > question.
> >
> >
> > "Andri" wrote:
> >
> > > Dear All,
> > >
> > > Here is the sample database.
> > >
> > > Date Salesman Region
> > > 16-Aug-08 A N
> > > 16-Aug-09 B E
> > > 16-June-07 C S
> > > 15-Aug-07 A S
> > > 15-Apr-07 B E
> > > 4-Sep-07 D N
> > > 4-May-07 E N
> > > 6-Sep-07 A N
> > > 3-Oct-07 B W
> > > 24-Sep-07 E E
> > >
> > > i would like to concatenate for Salesman B and Region E(east) in A1, so the
> > > result will be "15-Apr-07,16-Aug-09"... which formula can solve it?
> > >
> > > tried SMALL + sumproduct(but...this sum all the date in that arrays).
> > >
> > > thank you for your kind attention and help.
> > >
> > > respectfully,
> > > andri

 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      17th Apr 2010
That doesn't work
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Mike H" wrote:

> Hi,
>
> I don't know how to do that with a formula but here's a UDF that does it.
> Alt +F11 to open VB editor. Right click "ThisWorkbook' and insert module and
> paste the code in
>
> call with
>
> =ConCat(A2:A11,D2,E2)
>
> Where A2:A11 are the dates and D2 & E2 are the 2 lookup values
>
>
>
> Function ConCat(rng As Range, rep As String, area As String) As String
> Dim R As Long, R1 As Long, x As Long
> Application.Volatile
> rep = UCase(rep)
> area = UCase(area)
> For Each c In rng
> If UCase(c.Offset(, 1)) = rep And UCase(c.Offset(, 2)) = area Then
> MyString = MyString & c.Value & ","
> End If
> Next
> v = Split(MyString, ",")
> For R = 0 To UBound(v)
> For R1 = R To UBound(v)
> If v(R1) < v(R) Then
> str1 = v(R)
> str2 = v(R1)
> v(R) = str2
> v(R1) = str1
> End If
> Next R1
> Next R
> For x = 1 To UBound(v)
> ConCat = ConCat & v(x) & " , "
> Next
> ConCat = Left(ConCat, (Len(ConCat) - 2))
> End Function
>
> --
> Mike
>
> When competing hypotheses are otherwise equal, adopt the hypothesis that
> introduces the fewest assumptions while still sufficiently answering the
> question.
>
>
> "Andri" wrote:
>
> > Dear Mike,
> >
> > thank you for your kind and response.
> >
> > the formula is workable. but it only show for two dates only MIN and MAX.
> >
> > the required solution, to list down all the date, from the smallest,
> > increasing date and ended with the Largest date.
> >
> > so some records might contain several dates (3, 4, 5 or even 6dates).
> >
> > how to adjust it?
> >
> > TIA
> >
> > "Mike H" wrote:
> >
> > > Andri,
> > >
> > > As long as those are properly formatted dates try this ARRAY formula. the
> > > lookup values are in D2 (B) and E2 (E)
> > >
> > > =TEXT(MIN(IF(B2:B11=D2,IF(C2:C11=E2,A2:A11))),"dd-mmm-yy")&" ,
> > > "&TEXT(MAX(IF(B2:B11=D2,IF(C2:C11=E2,A2:A11))),"dd-mmm-yy")
> > >
> > >
> > > This is an array formula which must be entered by pressing CTRL+Shift+Enter
> > > and not just Enter. If you do it correctly then Excel will put curly brackets
> > > around the formula {}. You can't type these yourself. If you edit the formula
> > > you must enter it again with CTRL+Shift+Enter.
> > >
> > > --
> > > Mike
> > >
> > > When competing hypotheses are otherwise equal, adopt the hypothesis that
> > > introduces the fewest assumptions while still sufficiently answering the
> > > question.
> > >
> > >
> > > "Andri" wrote:
> > >
> > > > Dear All,
> > > >
> > > > Here is the sample database.
> > > >
> > > > Date Salesman Region
> > > > 16-Aug-08 A N
> > > > 16-Aug-09 B E
> > > > 16-June-07 C S
> > > > 15-Aug-07 A S
> > > > 15-Apr-07 B E
> > > > 4-Sep-07 D N
> > > > 4-May-07 E N
> > > > 6-Sep-07 A N
> > > > 3-Oct-07 B W
> > > > 24-Sep-07 E E
> > > >
> > > > i would like to concatenate for Salesman B and Region E(east) in A1, so the
> > > > result will be "15-Apr-07,16-Aug-09"... which formula can solve it?
> > > >
> > > > tried SMALL + sumproduct(but...this sum all the date in that arrays).
> > > >
> > > > thank you for your kind attention and help.
> > > >
> > > > respectfully,
> > > > andri

 
Reply With Quote
 
Jacob Skaria
Guest
Posts: n/a
 
      17th Apr 2010
Try this UDF (User Defined function) . From workbook launch VBE using
Alt+F11. From menu Insert a Module and paste the below function.Close and get
back to workbook and try the below formula.

Syntax:

=CONCAT(rngRange,intLookupColumn1, strLookupValue1,
intLookupColumn2, strLookupValue2,
intReturnColumn, strFormat As String, strDelimiter)

rngRange is the data range

intLookupColumn1 is the First lookup column
strLookupValue1 is the value to be looked up in the first lookup column

intLookupColumn2 is the second lookup column
strLookupValue2 is the value to be looked up in the second lookup column

intReturnColumn is the column to be returned
strFormat is optional if to be formatted
strDelimiter is optional delimiter. Default is space


Examples:
'1. With data in A1:C11; to vlookup 'B' and "E" from 2 and 3rd columns and
sort and concatenate each entry with " ," (space followed by a comma) the
formula would be

=concat(A1:C11,2,"B",3,"E",1,"dd-mmm-yy"," ,")


Function CONCAT(rngRange As Range, _
intLookupColumn1 As Integer, strLookupValue1 As String, _
intLookupColumn2 As Integer, strLookupValue2 As String, _
intReturnColumn As Integer, Optional strFormat As String, _
Optional strDelimiter As String = " ")
Dim lngRow As Long, arrDate() As Variant, varDate As Variant
Dim lngTemp1 As Long, lngTemp2 As Long

ReDim arrDate(0)
For lngRow = 1 To rngRange.Rows.Count
If StrComp(CStr(rngRange(lngRow, intLookupColumn1)), _
strLookupValue1, vbTextCompare) = 0 And _
StrComp(CStr(rngRange(lngRow, intLookupColumn2)), _
strLookupValue2, vbTextCompare) = 0 Then
ReDim Preserve arrDate(UBound(arrDate) + 1)
arrDate(UBound(arrDate)) = rngRange(lngRow, intReturnColumn)
End If
Next

If UBound(arrDate) > 1 Then
For lngTemp1 = 1 To UBound(arrDate)
For lngTemp2 = lngTemp1 To UBound(arrDate)
If arrDate(lngTemp1) > arrDate(lngTemp2) Then
varDate = arrDate(lngTemp1)
arrDate(lngTemp1) = arrDate(lngTemp2)
arrDate(lngTemp2) = varDate
End If
Next
Next
End If

For lngTemp1 = 1 To UBound(arrDate)
CONCAT = CONCAT & strDelimiter & Format(arrDate(lngTemp1), strFormat)
Next

CONCAT = Mid(CONCAT, Len(strDelimiter) + 1)
End Function


PS: You can modify this UDF to have the second lookup optional and to have
the sort optional...Thus this could be re-used for all type of LOOKUP()
CONCATENATE() requirements

--
Jacob (MVP - Excel)


"Andri" wrote:

> Dear All,
>
> Here is the sample database.
>
> Date Salesman Region
> 16-Aug-08 A N
> 16-Aug-09 B E
> 16-June-07 C S
> 15-Aug-07 A S
> 15-Apr-07 B E
> 4-Sep-07 D N
> 4-May-07 E N
> 6-Sep-07 A N
> 3-Oct-07 B W
> 24-Sep-07 E E
>
> i would like to concatenate for Salesman B and Region E(east) in A1, so the
> result will be "15-Apr-07,16-Aug-09"... which formula can solve it?
>
> tried SMALL + sumproduct(but...this sum all the date in that arrays).
>
> thank you for your kind attention and help.
>
> respectfully,
> andri

 
Reply With Quote
 
Teethless mama
Guest
Posts: n/a
 
      17th Apr 2010
Try this:

=IF(ISERR(MATCH(SMALL(IF((Salesman="B")*(Region="E"),COUNTIF(Date,"<"&Date)),ROWS($1:1)),COUNTIF(Date,"<"&Date),0)),"",INDEX(Date,MATCH(SMALL(IF((Salesman="B")*(Region="E"),COUNTIF(Date,"<"&Date)),ROWS($1:1)),COUNTIF(Date,"<"&Date),0)))


ctrl+shift+enter, not just enter
copy down as far as needed



"Andri" wrote:

> Dear All,
>
> Here is the sample database.
>
> Date Salesman Region
> 16-Aug-08 A N
> 16-Aug-09 B E
> 16-June-07 C S
> 15-Aug-07 A S
> 15-Apr-07 B E
> 4-Sep-07 D N
> 4-May-07 E N
> 6-Sep-07 A N
> 3-Oct-07 B W
> 24-Sep-07 E E
>
> i would like to concatenate for Salesman B and Region E(east) in A1, so the
> result will be "15-Apr-07,16-Aug-09"... which formula can solve it?
>
> tried SMALL + sumproduct(but...this sum all the date in that arrays).
>
> thank you for your kind attention and help.
>
> respectfully,
> andri

 
Reply With Quote
 
Teethless mama
Guest
Posts: n/a
 
      17th Apr 2010
This one slightly shorter:

=IF(SUMPRODUCT((Salesman="B")*(Region="E"))>=ROWS($1:1),INDEX(Date,MATCH(SMALL(IF((Salesman="B")*(Region="E"),COUNTIF(Date,"<"&Date)),ROWS($1:1)),COUNTIF(Date,"<"&Date),0)),"")

ctrl+shift+enter, not just enter
copy down as far as needed



"Teethless mama" wrote:

> Try this:
>
> =IF(ISERR(MATCH(SMALL(IF((Salesman="B")*(Region="E"),COUNTIF(Date,"<"&Date)),ROWS($1:1)),COUNTIF(Date,"<"&Date),0)),"",INDEX(Date,MATCH(SMALL(IF((Salesman="B")*(Region="E"),COUNTIF(Date,"<"&Date)),ROWS($1:1)),COUNTIF(Date,"<"&Date),0)))
>
>
> ctrl+shift+enter, not just enter
> copy down as far as needed
>
>
>
> "Andri" wrote:
>
> > Dear All,
> >
> > Here is the sample database.
> >
> > Date Salesman Region
> > 16-Aug-08 A N
> > 16-Aug-09 B E
> > 16-June-07 C S
> > 15-Aug-07 A S
> > 15-Apr-07 B E
> > 4-Sep-07 D N
> > 4-May-07 E N
> > 6-Sep-07 A N
> > 3-Oct-07 B W
> > 24-Sep-07 E E
> >
> > i would like to concatenate for Salesman B and Region E(east) in A1, so the
> > result will be "15-Apr-07,16-Aug-09"... which formula can solve it?
> >
> > tried SMALL + sumproduct(but...this sum all the date in that arrays).
> >
> > thank you for your kind attention and help.
> >
> > respectfully,
> > andri

 
Reply With Quote
 
Teethless mama
Guest
Posts: n/a
 
      17th Apr 2010
Try PIVOT table


"Andri" wrote:

> Dear All,
>
> Here is the sample database.
>
> Date Salesman Region
> 16-Aug-08 A N
> 16-Aug-09 B E
> 16-June-07 C S
> 15-Aug-07 A S
> 15-Apr-07 B E
> 4-Sep-07 D N
> 4-May-07 E N
> 6-Sep-07 A N
> 3-Oct-07 B W
> 24-Sep-07 E E
>
> i would like to concatenate for Salesman B and Region E(east) in A1, so the
> result will be "15-Apr-07,16-Aug-09"... which formula can solve it?
>
> tried SMALL + sumproduct(but...this sum all the date in that arrays).
>
> thank you for your kind attention and help.
>
> respectfully,
> andri

 
Reply With Quote
 
Andri
Guest
Posts: n/a
 
      17th Apr 2010
Dear TM,

still figuring out your formula and Mike's formula.

related your suggestion to use pivot table, i prefer to use formula instead
of PT.

thank you and respectfully,
andri

"Teethless mama" wrote:

> Try PIVOT table
>
>
> "Andri" wrote:
>
> > Dear All,
> >
> > Here is the sample database.
> >
> > Date Salesman Region
> > 16-Aug-08 A N
> > 16-Aug-09 B E
> > 16-June-07 C S
> > 15-Aug-07 A S
> > 15-Apr-07 B E
> > 4-Sep-07 D N
> > 4-May-07 E N
> > 6-Sep-07 A N
> > 3-Oct-07 B W
> > 24-Sep-07 E E
> >
> > i would like to concatenate for Salesman B and Region E(east) in A1, so the
> > result will be "15-Apr-07,16-Aug-09"... which formula can solve it?
> >
> > tried SMALL + sumproduct(but...this sum all the date in that arrays).
> >
> > thank you for your kind attention and help.
> >
> > respectfully,
> > andri

 
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
Finding Smallest Date in Non Contiguous Range Ryan Microsoft Excel Programming 3 2nd Nov 2009 03:57 PM
Returning the smallest value above a certain criteria Andrea K Microsoft Excel Worksheet Functions 4 28th Sep 2008 06:48 PM
Return a smallest date Freshman Microsoft Excel Worksheet Functions 8 12th Dec 2007 01:45 PM
formula to look up and return smallest date from a range of dates =?Utf-8?B?Qko=?= Microsoft Excel Worksheet Functions 5 7th Dec 2005 10:35 PM
I know how to concatenate ,can one de-concatenate to split date? =?Utf-8?B?UVVJQ0sgQk9PS1MgUFJPQkxFTS0=?= Microsoft Excel New Users 1 26th Jul 2005 05:07 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:25 AM.