+ Reply to Thread
Results 1 to 8 of 8

ConcatenateIf loop in macro then output value

  1. #1
    Registered User
    Join Date
    12-11-2014
    Location
    US
    MS-Off Ver
    2010
    Posts
    6

    ConcatenateIf loop in macro then output value

    Hi - thanks in advance for any guidance/solutions! Looking to translate the UDF ConcatenateIF into a loop in a macro.

    So I have an applicability matrix that is updated on a recurring basis - dummy workbook provided. Basically, does Report1 apply to Section2, etc. If it applies, the user inputs an "X" in the column. When the user is reviewing Section2, they'll need to know what reports they need to obtain. So in the summary tab I basically need to populate the applicable reports next to each section.

    I was using the UDF ConcatenateIf to do this; however, we need to keep auto-calc update on in the workbook/sheet so it continues to recalculate when someone makes a change to any cell in the w/b. With all this processing, the user will inadvertently hit escape as the UDF is running and interrupt the code (prompt tells them so, user thinks they broke the template).

    To get around this, I think I need to loop the ConcatenateIf function into a macro that is called by a button, and output the results of the ConcatenateIf. Any thoughts on accomplishing this? Basically, column B in Summary needs to be the output of ConcatenateIf - this will keep the UDF from running continuously.

    UDF used:

    Function ConcatenateIf(CriteriaRange As Range, Condition As Variant, _
    ConcatenateRange As Range, Optional Separator As String = ",") As Variant

    Dim i As Long
    Dim strResult As String
    On Error GoTo errHandler
    If CriteriaRange.Count <> ConcatenateRange.Count Then
    ConcatenateIf = CVErr(xlErrRef)
    Exit Function
    End If
    For i = 1 To CriteriaRange.Count
    If CriteriaRange.Cells(i).value = Condition Then
    strResult = strResult & Separator & ConcatenateRange.Cells(i).value
    End If
    Next i
    If strResult <> "" Then
    strResult = Mid(strResult, Len(Separator) + 1)
    End If
    ConcatenateIf = strResult
    Exit Function
    errHandler:
    ConcatenateIf = CVErr(xlErrValue)
    End FunctionConcatenateIf Output.xlsxConcatenateIf Output.xlsx

  2. #2
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: ConcatenateIf loop in macro then output value

    My suggestion will be to isolate your routine to the change cell using the application "selectionchange" and doing the updating accordingly.
    every time a cell changes (is updated) the routine is called

    Please Login or Register  to view this content.
    Last edited by rcm; 12-18-2014 at 01:10 PM. Reason: typo

  3. #3
    Registered User
    Join Date
    12-11-2014
    Location
    US
    MS-Off Ver
    2010
    Posts
    6

    Re: ConcatenateIf loop in macro then output value

    Can you elaborate on how exactly this work? Wouldn't this still cause the cells with the ConcatenateIf formulas to continuously update?

  4. #4
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: ConcatenateIf loop in macro then output value

    This function is only called when a cell value is changed. So in principle Concatenateif executes the changes for the cell only... maybe I was careless about the parameters but the scope range is the cell only..

  5. #5
    Registered User
    Join Date
    12-11-2014
    Location
    US
    MS-Off Ver
    2010
    Posts
    6

    Re: ConcatenateIf loop in macro then output value

    Due to the other processing required for the greater workbook, this is still causing an issue. Is it possible to translate the ConcatenateIf function to VBA so we can loop it within a macro and essentially paste values in the selected output column? That loop would be within a macro that runs from a command button.

  6. #6
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: ConcatenateIf loop in macro then output value

    let us start from scratch!!
    if you insert this routine in a worksheet private sub like "change" then it will run everytime a change is detected in the applicability sheet
    Please Login or Register  to view this content.
    Last edited by rcm; 12-19-2014 at 01:21 PM. Reason: clarity

  7. #7
    Registered User
    Join Date
    12-11-2014
    Location
    US
    MS-Off Ver
    2010
    Posts
    6

    Re: ConcatenateIf loop in macro then output value

    Thanks rcm, this was exactly what I was looking for!

  8. #8
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: ConcatenateIf loop in macro then output value

    you are most welcome, please mark the thread as solved!!

+ 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. ConcatenateIf to skip blanks (done in a loop)
    By samsmyman in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-24-2014, 10:28 AM
  2. Macro to Loop Through Cells and if the value is true, output data to another worksheet
    By clintonwarren in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-08-2012, 02:42 PM
  3. Need macro to loop through input cell values and copy output value
    By jaf in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-27-2011, 02:59 PM
  4. Output loop to Word?
    By RowdyRed94 in forum Excel General
    Replies: 7
    Last Post: 12-27-2006, 03:23 PM
  5. [SOLVED] New Function: ConcatenateIF
    By Simon Shaw in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-31-2005, 09:06 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