Results 1 to 3 of 3

Excel VBA: CONCATENATE + IF/LOOKUP

Threaded View

  1. #1
    Registered User
    Join Date
    08-28-2012
    Location
    Sweden
    MS-Off Ver
    Excel 2010
    Posts
    16

    Excel VBA: CONCATENATE + IF/LOOKUP

    Hi there,

    not having found a suitable set of excel formulas solving my issue ad-hoc, I went ahead looking into Macros. This is what I want to do:

    - CONCATENATE a set of fields in one column
    - IF the field in the colum left of my text-field matches a certain criteria

    Basically replicating the checking functionality of SUMIF, just with concatenate.

    I have found relevant VBA-snippets that I have tried to combine. However, I am lacking the criteria-checking functionality. Here is what I got:

    Function JoinIF(source As Range, checkrange As Range, criterion As String, Optional delimiter As String) As String
        Dim sResult As String
        Dim oCell As Range
        Dim cCell As Range
    
        For Each oCell In source.Cells
            If Len(oCell.Value) > 0 Then
                If cCell.Value = criterion Then
                       sResult = sResult + CStr(oCell.Value) + delimiter
                End If
            End If
         Next
    
        Join = sResult
    End Function
    This naturally does't work, as I am not checking the correct cCell value (second IF-Check).

    Hence my question: How can I get the correct cCell to check against in the game here?

    Thank you for your help!

    Best regards,
    Andreas
    Last edited by amq; 08-28-2012 at 09:22 AM.

Thread Information

Users Browsing this Thread

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

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