ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,226
- Office Version
- 2007
- Platform
- Windows
Hi,
Ive moved a code from one worksheet to another,code supplied.
Ive names things the same so not sure why no it doesnt work and i get a RTE9 out of range.
The code in question is shown in yellow below.
Can you advise where i shouold be looking to correct this please.
Ive moved a code from one worksheet to another,code supplied.
Ive names things the same so not sure why no it doesnt work and i get a RTE9 out of range.
The code in question is shown in yellow below.
Can you advise where i shouold be looking to correct this please.
Rich (BB code):
Private Sub SortList_Click()
Dim oLo As ListObject
Dim oLc1 As ListColumn, oLc2 As ListColumn
Dim i As Integer, x As Integer
Dim splitThis As String, alpha As String, num As String
Application.ScreenUpdating = False
'setup what/where to workwith
Set oLo = ActiveWorkbook.Worksheets("INFO").ListObjects("Table20")
'add 2 columns "Alpha" and "Num"
With oLo
Set oLc1 = .ListColumns.Add
oLc1.Name = "Alpha"
Set oLc2 = .ListColumns.Add
oLc2.Name = "Num"
'populate the new columns
For x = 1 To oLo.DataBodyRange.Rows.Count
splitThis = .ListColumns("SORT").DataBodyRange.Rows(x)
alpha = "": num = ""
For i = 1 To Len(splitThis)
If IsNumeric(Mid(splitThis, i, 1)) Then
num = num & Mid(splitThis, i, 1)
Else
alpha = alpha & Mid(splitThis, i, 1)
End If
Next i
.ListColumns("Alpha").DataBodyRange.Rows(x) = alpha
.ListColumns("Num").DataBodyRange.Rows(x) = num
Next x
'sort
With .Sort
.SortFields.Clear
.SortFields.Add _
Key:=Range("Table20[Alpha]"), SortOn:=xlSortOnValues, Order:= _
xlAscending, DataOption:=xlSortNormal
.SortFields.Add _
Key:=Range("Table20[Num]"), SortOn:=xlSortOnValues, Order:= _
xlAscending, DataOption:=xlSortNormal
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
'remove the 2 added columns
.ListColumns("Num").Delete
.ListColumns("Alpha").Delete
End With
Application.ScreenUpdating = True
End Sub