Results 1 to 3 of 3

How to generalize macro that Grouped Rows To Delimited String for more then one column

Threaded View

Einarr How to generalize macro that... 06-25-2021, 11:45 AM
nilem Re: How to generalize macro... 06-25-2021, 12:46 PM
Einarr Re: How to generalize macro... 06-25-2021, 12:56 PM
  1. #1
    Registered User
    Join Date
    02-12-2018
    Location
    Mpls, USA
    MS-Off Ver
    360 2016
    Posts
    11

    How to generalize macro that Grouped Rows To Delimited String for more then one column

    My data looks like

    data.png

    My Macro turns the repeated rows of data for the last column into a delimited string


    outputhave.png

    I can get the macro to create delimited strings for both columns

    outputneed.png

    But in some projects, I might have 50 columns that I need to run this on

    How to generalize this to work on n-Columns

    Thanks

    Sub GroupedRowsToDelimited Strings()
              Dim v, r&, L&
        With Worksheets("citClustered").UsedRange.Rows
            ReDim v(1 To .count - 1, 1 To 3)
            For r = 2 To .count
                If .Cells(r, 1).value = .Cells(r - 1, 1).value Then
                              v(L, 3) = v(L, 3) & "|" & .Cells(r, 3).value
                Else
                    If L Then v(L, 3) = v(L, 3)
                                    L = L + 1
                              v(L, 1) = .Cells(r, 1).value
                              v(L, 2) = .Cells(r, 2).value
                              v(L, 3) = .Cells(r, 3).value
                End If
            Next
                    If L Then v(L, 3) = v(L, 3)
        End With
             Application.ScreenUpdating = False
        With Worksheets("citGrouped")
            .UsedRange.Offset(1).Clear
            .[A2:C2].Resize(L).value = v
        End With
             Application.ScreenUpdating = True
    End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 5
    Last Post: 01-05-2019, 12:15 PM
  2. Generalize macro to use any row it is run from
    By jpankey in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-28-2017, 02:55 PM
  3. How do I generalize a VBA macro to AutoSize comment frames/boxes?
    By gssi.chinner in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-23-2015, 09:28 AM
  4. [SOLVED] Reading a serial port delimited string into rows
    By land35 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-18-2015, 08:46 AM
  5. Formula to take a column to row, delimited by certain text string
    By LightingPop in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 01-23-2015, 03:49 PM
  6. [SOLVED] Semi-colon Delimited String Contains Text Occuring in Column
    By The831st in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-04-2014, 06:28 AM
  7. Converting Pipe Delimited Data String into Seperate columns using VBA Macro
    By RestlessNative in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-06-2014, 05:40 PM

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1