0
我想爲特定工作表的表格自定義排序,但我得到運行時錯誤「483」「對象不支持這個屬性或方法「。運行時錯誤「483」「對象不支持此屬性或方法」
我將工作表名稱和自定義列表順序作爲來自用戶的字符串輸入。
Option Explicit
Sub SortRiskArea()
Dim wk As Worksheet
Dim Tb, Rb
Dim shtName As String
shtName = InputBox(Prompt:="Enter the Worksheet Name that you want to sort." & vbNewLine & " Ex: Risk Register ", Title:="Hello", Default:="Risk Register")
shtName = Trim(shtName)
Dim strName As String
strName = InputBox(Prompt:="Enter the Sort Order for Risk Area" & vbNewLine & " Ex: Commercial, Technological, Management, Reputational, Governance, Operational", Title:="Hello", Default:="Commercial, Technological, Management, Reputational, Governance, Operational")
strName = Replace(strName, " ", "")
Set wk = Sheets(shtName)
If shtName = "Risk Register" Then Tb = "Table1"
If shtName = "SAP BI" Then Tb = "Table13"
If shtName = "SAP BO" Then Tb = "Table14"
If shtName = "SAP BW" Then Tb = "Table15"
If shtName = "SAP PM" Then Tb = "Table16"
If shtName = "Mobility" Then Tb = "Table17"
If shtName = "SAP FI" Then Tb = "Table18"
If shtName = "SAP Service Desk" Then Tb = "Table19"
Rb = "[Risk Area]"
Rb = Tb & Rb
Error Lines > ActiveWorkbook.wk.ListObjects(Tb).Sort. _
SortFields.Add Key:=Range(Rb), SortOn:=xlSortOnValues, _
Order:=xlAscending, CustomOrder:= _
strName, _
DataOption:=xlSortNormal
With ActiveWorkbook.wk.ListObjects(Tb).Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("B5").Select
End Sub
什麼行錯誤? – Davesexcel
@Davesexcel我編輯了這個問題請看看 – newguy