Results 1 to 5 of 5

Take cell value spit on delimiter SORT the ensuing array then Join on delimiter post back

Threaded View

  1. #1
    Forum Contributor
    Join Date
    07-11-2010
    Location
    Minneapolis, USA
    MS-Off Ver
    Excel 2016
    Posts
    308

    Red face Take cell value spit on delimiter SORT the ensuing array then Join on delimiter post back

    I want to get a cell value then spit on a delimiter then SORT the ensuing array then Join the sorted array on the same delimiter then post back the ensuing string to the same cell

    e.g I have the cell value
    AA|MM|CC|WW|BB|NN
    I want it to be
    AA|BB|CC|MM|NN
    I get type mismatch error here
     For i = LBound(ar) To UBound(ar)
    The sorted array is empty, it seems the sorting is deleting the array? ... I am not sure what is going on, I have tried various sorting functions and I get the same error for all of them

    Thanks

    Sub Test()
    Dim ar As Variant
    Dim strTemp As String
    
       ar = Split(Cells(2, "E").Value, "|")
       ar = SortAry(ar)
       
       For i = LBound(ar) To UBound(ar)
          MsgBox ar(i)
       Next
       
       strTemp = Join(ar, "|")
       
       Cells(2, "E").Value = strTemp
       
    End Sub
    
    Function SortAry(pvarArray As Variant) As Variant
        Dim i As Long
        Dim iMin As Long
        Dim iMax As Long
        Dim varSwap As Variant
        Dim blnSwapped As Boolean
        
        iMin = LBound(pvarArray)
        iMax = UBound(pvarArray) - 1
        Do
            blnSwapped = False
            For i = iMin To iMax
                If pvarArray(i) > pvarArray(i + 1) Then
                    varSwap = pvarArray(i)
                    pvarArray(i) = pvarArray(i + 1)
                    pvarArray(i + 1) = varSwap
                    blnSwapped = True
                End If
            Next
            iMax = iMax - 1
        Loop Until Not blnSwapped
    End Function
    Last edited by capson; 02-05-2016 at 03:43 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] How do I create a macro to import and sort a txt file with more than one delimiter?
    By JonnyEnglish in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-29-2016, 03:57 AM
  2. FORMULA: Find all matches within array, delimiter between duplicate sets
    By cslicer in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 10-16-2014, 10:59 AM
  3. Text to columns VBA code to change delimiter if the cell value is in array
    By dopple in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-26-2008, 09:25 AM
  4. Split Cell by Delimiter, Move to New Row...
    By jpfulton in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-16-2008, 03:43 AM
  5. Split Cell by Delimiter, Move to New Row...
    By jpfulton in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 09-08-2008, 03:53 PM
  6. [SOLVED] semicolon delimiter in a cell
    By coco in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-02-2005, 06:05 PM
  7. Splitting a Cell (no useable delimiter).....
    By Puggy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-17-2005, 11:31 AM

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