+ Reply to Thread
Results 1 to 9 of 9

Multi-Dimensional concatif coding

Hybrid View

  1. #1
    Registered User
    Join Date
    01-27-2015
    Location
    Houston, USA
    MS-Off Ver
    2010
    Posts
    3

    Multi-Dimensional concatif coding

    Hi I'm a totally new into VBA/Coding and my problem is somewhat complicated (at least for me).. I hope there's anyone can help me on this

    Table1.JPG

    Row 17 - Row 383 is my basic schedule table where it starts. '7'(hours) & team A/B/C are the variables which people enters in, delete out or change. I previously used 'concatif' function I got from someone else to list out the names who entered a value '7' from the schedule table above. The result currently shows as Row 9 - Row 10 with this 'concatif' function. The dates in the result table is simply '=Today()' and '=Workday(x,y)' formula. And of course the dates in the result table changes everyday accordingly.

    Now I'm trying to improve this little bit on the result table by listing out the names separately based by each person's team. Hopefully, I wish the a new result table show as below.

    Table3.JPG

    I've never done with the coding before.. so if there's anyone who can help with this.. I will learn a lot from it and of course would be greatly appreciated. Thanks,


    Current Cell C10

    =ConcatIf(INDIRECT("C" & MATCH(C$9,$B$19:$B$383,0)+18 & ":O" & MATCH(C$9,$B$19:$B$383,0)+18), $C$17:$O$17, ", ")


    Current 'concatif' Coding

    Function ConcatIf(ByVal compareRange As Range, Optional ByVal stringsRange As Range, Optional Delimiter As String, Optional NoDuplicates As Boolean) As String
    
    Rem the first three argumens of ConcatIf mirror those of SUMIF
    Rem the Delimiter and NoDuplicates arguments are optional (default "" and False)
    
    Dim i As Long, j As Long
    
    With compareRange.Parent
    Set compareRange = Application.Intersect(compareRange, Range(.UsedRange, .Range("a1")))
    End With
    
    If compareRange Is Nothing Then Exit Function
    If stringsRange Is Nothing Then Set stringsRange = compareRange
    Set stringsRange = compareRange.Offset(stringsRange.Row - compareRange.Row, stringsRange.Column - compareRange.Column)
    
    For i = 1 To compareRange.Rows.Count
    For j = 1 To compareRange.Columns.Count
    If (Application.CountIf(compareRange.Cells(i, j), ">0") = 1) Then
    If InStr(ConcatIf, Delimiter & CStr(stringsRange.Cells(i, j))) <> 0 Imp Not (NoDuplicates) Then
    ConcatIf = ConcatIf & Delimiter & CStr(stringsRange.Cells(i, j))
    End If
    End If
    Next j
    Next i
    ConcatIf = Mid(ConcatIf, Len(Delimiter) + 1)
    
    End Function
    Attached Images Attached Images

  2. #2
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: Multi-Dimensional concatif coding

    Here is another way of doing it...( An array entered formula.. use Ctrl + shift + enter to confirm it.)
    Formula: copy to clipboard
    =JoinC(IF(IF($C$18:$I$18=$B2,INDEX($C$19:$I$383,MATCH(C$1,$B$19:$B$383,0))),$C$17:$I$17),", ")


    Here is the JoinC Code with will concatenate the results.
    Function JoinC(ByRef x As Variant, ByRef Delim As String) As String
        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        '           Developed by Vikas Gautam                               '
        '         Forum Expert at ExcelForum.Com                            '
        'For Concatenating Arrays or Ranges having One Row and Many Columns '
        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        dLen = Len(Delim)
        With Application
            SourceArray = .Transpose(.Transpose(x))
            Delim2 = Delim & Delim
            Temp = Replace(Join(SourceArray, Delim), Delim2, Delim)
            
            Do While InStr(1, Temp, Delim2, 1) > 0
                Temp = Replace(Temp, Delim2, Delim)
            Loop
        End With
        
        If Left(Temp, dLen) = Delim Then Temp = Mid(Temp, dLen + 1, Len(Temp))
        If Right(Temp, dLen) = Delim Then Temp = Left(Temp, Len(Temp) - dLen)
        JoinC = Temp
    
    End Function
    You didn't provided the Row and Column No. of your output table below.
    So I Assumed like this:-
    	B	       C	            D               E
    1		   2/1/20XX	       2/2/20Xx	        2/3/20XX
    2	Team A			
    3	Team B			
    4	Team C
    Note:- Put the above formula in C2 by using CTRL + SHIFT + ENTER and Drag downwards and Sideways.

    Table3.JPG



    Here is the link you can find the JoinC Code:-
    Concatenating Rows (JoinR) and Columns (JoinC)
    Last edited by Vikas_Gautam; 02-04-2015 at 01:05 AM.
    Regards,
    Vikas Gautam
    Excel-buzz.blogspot.com

    Excel is not a matter of Experience, its a matter of Application.

    Say Thanks, Click * Add Reputation

  3. #3
    Registered User
    Join Date
    01-27-2015
    Location
    Houston, USA
    MS-Off Ver
    2010
    Posts
    3

    Re: Multi-Dimensional concatif coding

    Hi Vikas, your function with JoinC comes with an error in value. I did use ctrl Shift Enter to go along with the array data. And when I took out 'INDEX($C$19:$I$30,MATCH(C$1,$B$19:$B$30,0))'.. it results in a reference error. Can you help me out once again?
    Last edited by wildeye87; 02-03-2015 at 04:11 PM.

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Multi-Dimensional concatif coding

    I recognize the code that I wrote for the ConcatIf function.
    It looks like I'll have to write a ConcatIfs function.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Registered User
    Join Date
    01-27-2015
    Location
    Houston, USA
    MS-Off Ver
    2010
    Posts
    3

    Re: Multi-Dimensional concatif coding

    Is that something possible or at least easy enough you to improve? If you could modify this 'ConcatIf' as 'ConcatIfs', it would be great for me though!

  6. #6
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Multi-Dimensional concatif coding

    It will be easier if I could hard code a delimiter.
    While your need is for a comma delimiter, I've seen other coders who need commas in the data. Hmm.....

    Upgrading to a ConcatIfs is one of those projects that I've been putting off.
    I hope there isn't a rush, since I probably wont have time until the weekend.
    If that time scale works for you, great.
    If you need it sooner, give it a shot yourself and I can guide you through any problems. If you do it your self, dump the NoDuplicates argument and the If Instr.... line.

  7. #7
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: Multi-Dimensional concatif coding

    Hi WildEye..
    I guess, there is a problem with references.
    Provide a sample of your workbook, if you can. Then It would a lot easier for me to work upon.

  8. #8
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: Multi-Dimensional concatif coding

    Okay I guess I have been able to achieve it.
    Next time, be sure that you provide a sample workbook so that we don't have to create it ourselves.

    Here is the revised JoinC code, I have revised it in the post2 as well.

    Function JoinC(ByRef x As Variant, ByRef Delim As String) As String
        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        '           Developed by Vikas Gautam                               '
        '         Forum Expert at ExcelForum.Com                            '
        'For Concatenating Arrays or Ranges having One Row and Many Columns '
        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        dLen = Len(Delim)
        With Application
            SourceArray = .Transpose(.Transpose(x))
            Delim2 = Delim & Delim
            Temp = Replace(Join(SourceArray, Delim), Delim2, Delim)
            
            Do While InStr(1, Temp, Delim2, 1) > 0
                Temp = Replace(Temp, Delim2, Delim)
            Loop
        End With
        
        If Left(Temp, dLen) = Delim Then Temp = Mid(Temp, dLen + 1, Len(Temp))
        If Right(Temp, dLen) = Delim Then Temp = Left(Temp, Len(Temp) - dLen)
        JoinC = Temp
    
    End Function
    Check the attached file:-
    Attached Files Attached Files

  9. #9
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Multi-Dimensional concatif coding

    Here is the CountIfs UDF that I've developed.
    The syntax is =CountIfs(stringsRange, CriteriaRange1, Criteria1, CritereriaRange2, Criteria2,...., [optional Delimiter])

    The last argument is and optional delimiter that defaults to space.

    Note that any of the ranges can be rectangular, they need not be single column or row ranges.
    Note also that if the CriteriaRanges and Criterias are omitted, it will return a delimited string of the values in the StringsRange.
    Function ConcatIfs(stringsRange As Range, ParamArray Criterias() As Variant) As String
        Dim Delimiter As String
        Dim Size As Long
        Dim RowCount As Long, ColumnCount As Long
        Dim RowOfInterest As Long, ColumnOfInterest As Long
        Dim i As Long, j As Long, k As Long
        Dim flag As Boolean
        
        Delimiter = " ": Rem default delimiter
        Size = UBound(Criterias)
        If UBound(Criterias) Mod 2 = 0 Then
            Delimiter = Criterias(UBound(Criterias))
            Size = Size - 1
        End If
        
        With stringsRange
            Set stringsRange = Application.Intersect(.Cells, .Parent.UsedRange)
        End With
        RowCount = stringsRange.Rows.Count
        ColumnCount = stringsRange.Columns.Count
        For k = 0 To Size Step 2
            With Criterias(k)
                Set Criterias(k) = Application.Intersect(.Cells, .Parent.UsedRange)
            End With
            
            With Criterias(k)
                If RowCount < .Rows.Count Then RowCount = .Rows.Count
                If ColumnCount < .Columns.Count Then ColumnCount = .Columns.Count
            End With
        Next k
        
        For i = 1 To RowCount
            For j = 1 To ColumnCount
                flag = True
                For k = 0 To Size Step 2
                    RowOfInterest = Application.Min(i, Criterias(k).Rows.Count)
                    ColumnOfInterest = Application.Min(j, Criterias(k).Columns.Count)
                    flag = flag And (WorksheetFunction.CountIf(Criterias(k).Cells(RowOfInterest, ColumnOfInterest), Criterias(k + 1)) = 1)
                Next k
                If flag Then
                    RowOfInterest = Application.Min(i, stringsRange.Rows.Count)
                    ColumnOfInterest = Application.Min(j, stringsRange.Columns.Count)
                    ConcatIfs = ConcatIfs & Delimiter & CStr(stringsRange.Cells(RowOfInterest, ColumnOfInterest).Value)
                End If
            Next j
        Next i
        ConcatIfs = Mid(ConcatIfs, Len(Delimiter) + 1)
    End Function
    EDIT:
    The attached is an example workbook
    Attached Files Attached Files
    Last edited by mikerickson; 02-05-2015 at 03:23 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Multi-dimensional VLOOKUP
    By LadyS in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-25-2014, 12:37 PM
  2. [SOLVED] Dim multi dimensional array
    By jdfjab in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-06-2012, 09:08 AM
  3. Multi-Dimensional Arrays
    By ajocius in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-09-2009, 11:20 AM
  4. [SOLVED] Multi Dimensional Array
    By andym in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-10-2006, 03:29 AM
  5. Multi-Dimensional Array Let & Get
    By Trip in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-21-2005, 04:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1