I need to list out all unique values in cells A2,A3,andA4. Currently using a sort concatenate function found in --VBA and Macros for Excel that can probably be modified. Below is the SortConcat code, and a condensed version of the sheet.I need to modify the code so that it:
1)skips zeros
2)skips dates
3) will handle a single row,horizontal array 164 columns wide
4) sort in ascending order with numbers contained in parenthesis at the end
This spreadsheet will get approximately 30 rows of data a week. The formula will eventually be put in A1 and all data is copied/paste special values only to the next row, so all formulas are only in row 1.(TMI)
Sheet
1)skips zeros
2)skips dates
3) will handle a single row,horizontal array 164 columns wide
4) sort in ascending order with numbers contained in parenthesis at the end
This spreadsheet will get approximately 30 rows of data a week. The formula will eventually be put in A1 and all data is copied/paste special values only to the next row, so all formulas are only in row 1.(TMI)
Code:
Option Explicit
Function SortConcat(Rng As Range) As Variant
'Rng —The range of data to be sorted and concatenated.
Dim MySum As String, arr1() As String
Dim j As Integer, i As Integer
Dim cl As Range
Dim concat As Variant
On Error GoTo FuncFail:
'initialize output
SortConcat = 0#
'avoid user issues
If Rng.Count = 0 Then Exit Function
'get range into variant variable holding array
ReDim arr1(1 To Rng.Count)
'fill array
i = 1
For Each cl In Rng
arr1(i) = cl.Value
i = i + 1
Next
'sort array elements
Call BubbleSort(arr1)
'create string from array elements
For j = UBound(arr1) To 1 Step -1
If Not IsEmpty(arr1(j)) Then
MySum = arr1(j) & "," & MySum
End If
Next j
'assign value to function
SortConcat = Left(MySum, Len(MySum) - 1)
'exit point
concat_exit:
Exit Function
'display error in cell
FuncFail:
SortConcat = Err.Number & "-" & Err.Description
Resume concat_exit
End Function
Sub BubbleSort(List() As String)
' Sorts the List array in ascending order
Dim First As Integer, Last As Integer
Dim i As Integer, j As Integer
Dim Temp
First = LBound(List)
Last = UBound(List)
For i = First To Last - 1
For j = i + 1 To Last
If UCase(List(i)) > UCase(List(j)) Then
Temp = List(j)
List(j) = List(i)
List(i) = Temp
End If
Next j
Next i
End Sub
Sheet
test for demension macro.xls | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | |||
1 | currentoutput | neededoutput | 111 | DATE | 112 | DATE | 113 | DATE | 114 | DATE | 121 | DATE | 122 | DATE | 123 | DATE | 124 | DATE | 131 | DATE | 132 | DATE | 133 | DATE | 134 | DATE | ||
2 | (6/6),(6/8),0,0,0,12:00:00AM,12:00:00AM,12:00:00AM,4/16/2007,4/17/2007,4/19/2007,4/19/2007,4/19/2007,4/19/2007,4/20/2007,4/20/2007,4/20/2007,6,6,6,6,6,6,8 | 6,8,(6/6),(6/8) | 8 | 4/17 | 6 | 4/19 | 6 | 4/20 | 0 | 1/0 | 6 | 4/16 | (6/8) | 4/19 | (6/6) | 4/20 | 0 | 1/0 | 6 | 4/20 | 6 | 4/19 | 6 | 4/19 | 0 | 1/0 | ||
3 | 10,10,10,10,12,12,12,12,12,12,12,12,4/19/2007,4/20/2007,4/20/2007,4/20/2007,4/20/2007,4/20/2007,4/20/2007,4/20/2007,4/20/2007,4/20/2007,4/20/2007,4/20/2007 | 10,12 | 10 | 4/20 | 10 | 4/20 | 10 | 4/20 | 10 | 4/20 | 12 | 4/20 | 12 | 4/20 | 12 | 4/20 | 12 | 4/19 | 12 | 4/20 | 12 | 4/20 | 12 | 4/20 | 12 | 4/20 | ||
4 | 4,4,4,4,4,4,4,4,4,4,4,4,4/10/2007,4/17/2007,4/18/2007,4/18/2007,4/18/2007,4/18/2007,4/19/2007,4/19/2007,4/19/2007,4/20/2007,4/20/2007,4/9/2007 | 4 | 4 | 4/20 | 4 | 4/18 | 4 | 4/9 | 4 | 4/19 | 4 | 4/19 | 4 | 4/19 | 4 | 4/18 | 4 | 4/17 | 4 | 4/18 | 4 | 4/18 | 4 | 4/20 | 4 | 4/10 | ||
5 | ||||||||||||||||||||||||||||
6 | ||||||||||||||||||||||||||||
7 | ||||||||||||||||||||||||||||
Sheet1 |