Results 1 to 3 of 3

Thread: Ignoring ranks when concatenating cells in Microsoft Excel

  1. #1
    Join Date
    Feb 2012
    Posts
    10

    Ignoring ranks when concatenating cells in Microsoft Excel

    I have run out of ideas on this one and now I've lost my fresh morning mind, so any help would be much appreciated. I have a list of garments and each style has a different number of sizes in its size range from a minimum of 1 available size to a maximum of 24 available sizes, so I have 24 columns for sizes. I want to concatenate the available sizes for each style separated by a comma and a space.

    A simplified version of the data as it currently stands is like this:
    • A B C D E etc.....out to 24 columns
    • 1 Stock Item Name Available Sizes
    • 2 Stock Item A 8 10 12 14
    • 3 Stock Item B S M L
    • 4 Stock Item C OS

    and the result I want in one column (single cell) is:
    • A B
    • 1 Stock Item Name Available Sizes
    • 2 Stock Item A 8, 10, 12, 14
    • 3 Stock Item B S, M, L
    • 4 Stock Item C OS

    The problem when I use concatenate or "&" across the 24 columns is that I end up with commas and spaces after the available sizes for all of the remaining blank cells. I can't use IF because I can't embed that many IF statements in the one formula.

  2. #2
    Join Date
    Aug 2011
    Posts
    580

    Re: Ignoring ranks when concatenating cells in Microsoft Excel

    As long as there are no embedded spaces in any of those columns (C:Z), you could use: =substitute(trim(c2&" "&d2&" "&e2&" "...&" "&z2)," ",", ")).
    Code:
    Public Function MultiCat( _
    ByRef rRng As Excel.Range, _
    Optional ByVal sDelim As String = "") _
    As String
    Dim rCell As Range
    For Each rCell In rRng
    if rcell.value = "" then
    'do nothing
    else
    MultiCat = MultiCat & sDelim & rCell.Text
    end if
    Next rCell
    if len(multicat) > 0 then
    MultiCat = Mid(MultiCat, Len(sDelim) + 1)
    end if
    End Function
    And use it in a cell like:
    =multicat(c2:z2,", ")

  3. #3
    Join Date
    Aug 2011
    Posts
    540

    Re: Ignoring ranks when concatenating cells in Microsoft Excel

    One way is use TRIM on the individual cell concats - TRIM will remove all extraneous white spaces except the single space in-between values, then use SUBSTITUTE to replace these single spaces: " " with a comma-space, ie: ", ". Insert a new col B, so your 24 cols would now be cols C to Z. Then place in B2 something like this (assuming concats only for the 1st 4 cols: C to F): =SUBSTITUTE(TRIM(C2&" "&D2&" "&E2&" "&F2)," ",", ") Copy B2 down to return the desired neat results. Extend the part within the TRIM(...) to suit Your final expression in B2 should look something like this: =SUBSTITUTE(TRIM(C2&" "&D2&" "&E2&" "&F2& ... &" "&Z2)," ",", "). Note that it's easier & neater to use the ampersand operator: & for the cell concats, instead of CONCATENATE

Similar Threads

  1. Replies: 2
    Last Post: 01-02-2012, 02:08 PM
  2. How to renumber cells in Microsoft Excel
    By Weslee in forum MS Office Support
    Replies: 2
    Last Post: 24-01-2012, 05:25 PM
  3. Replies: 1
    Last Post: 14-01-2012, 02:29 PM
  4. How to Manipulate cells in Microsoft Excel 2007
    By Deepest BLUE in forum Windows Software
    Replies: 3
    Last Post: 27-11-2009, 02:48 AM
  5. Short cut to merge cells in Microsoft Excel
    By Jesus2 in forum Windows Software
    Replies: 3
    Last Post: 24-11-2009, 06:31 AM

Tags for this Thread

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
  •  
Page generated in 1,714,002,586.48327 seconds with 17 queries