Home |
Search |
Today's Posts |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
What does "StrSort" do?
It sorts the strings in alphabetical order using the following functions: Public Static Sub StrSort(ByRef words() As String, Ascending As Boolean, AllLowerCase As Boolean) 'Pass in string array you want to sort by reference and 'read it back 'Set Ascending to True to sort ascending, ' 'false to sort descending 'If AllLowerCase is True, strings will be sorted 'without regard to case. Otherwise, upper 'case characters take precedence over lower 'case characters Dim I As Integer Dim J As Integer Dim NumInArray, LowerBound As Integer NumInArray = UBound(words) LowerBound = LBound(words) For I = LowerBound To NumInArray J = 0 For J = LowerBound To NumInArray If AllLowerCase = True Then If Ascending = True Then If StrComp(LCase(words(I)), _ LCase(words(J))) = -1 Then Call Swap(words(I), words(J)) End If Else If StrComp(LCase(words(I)), _ LCase(words(J))) = 1 Then Call Swap(words(I), words(J)) End If End If Else If Ascending = True Then If StrComp(words(I), words(J)) = -1 Then Call Swap(words(I), words(J)) End If Else If StrComp(words(I), _ words(J)) = 1 Then Call Swap(words(I), words(J)) End If End If End If Next J Next I End Sub Private Sub Swap(var1 As String, var2 As String) Dim x As String x = var1 var1 = var2 var2 = x End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Help, please, I'm stuck | Excel Discussion (Misc queries) | |||
Still stuck | Excel Programming | |||
stuck please help | Excel Programming | |||
Stuck! | Excel Programming | |||
I am new to VBA and am stuck | Excel Programming |