I have the following code that works fine………but
I've been trying to sort it by code name but everything I try it sorts by the index numbers, I WANT IT SORTED BY CODENAME, any help appreciated
I included a picture of what it's doing
I've been trying to sort it by code name but everything I try it sorts by the index numbers, I WANT IT SORTED BY CODENAME, any help appreciated
I included a picture of what it's doing
VBA Code:
'''''Restricted worksheets list'''''
Cells.Range("K5:N104").ClearContents
Const SwitchBoardNameG As String = "general.misc"
Const FilterCellG As String = "J5"
Const OutputRowG As Long = 6
Const IndexClmG As String = "M"
Const NameClmG As String = "L"
Const VisibleClmG As String = "N"
Const CodeNameClmG As String = "K"
Dim SbG As Worksheet
Dim FltG As String
Dim TabNamesG() As String
Dim rG As Long
Dim WsG As Worksheet
Dim RngG As Range
Set SbG = ThisWorkbook.Worksheets(SwitchBoardNameG)
FltG = SbG.Range(FilterCellG).Cells(1).Value
ReDim TabNamesG(ThisWorkbook.Worksheets.Count)
rG = OutputRow
[L4] = [{"Name"}]
[K4] = [{"CodeName"}]
[M4] = [{"Index"}]
[N4] = [{"Visibility"}]
For Each WsG In ThisWorkbook.Worksheets
If (WsG.CodeName Like (Range("L3"))) Then
If InStr(1, WsG.CodeName, FltG, vbTextCompare) = 1 Then
SbG.Cells(rG, CodeNameClmG).Resize(, 4).Value = Array(WsG.CodeName, WsG.Name, WsG.Index, WsG.Visible)
rG = rG + 1
End If
End If
Next WsG
If rG Then
Set RngG = SbG.Range(SbG.Cells(OutputRowG, CodeNameClmG), SbG.Cells(rG - 1, CodeNameClmG))
With Sb.Sort
With .SortFields
.Clear
.Add Key:=RngG.Cells(1), _
SortOn:=xlSortOnValues, _
Order:=xlDescending, _
DataOption:=xlSortTextAsNumbers
End With
.SetRange RngG
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End If