在這個用戶的形式排序不工作
我有以下代碼(升序默認是TRUE,而降序爲False)
Private Sub OKButton_Click()
Dim rRange As Range
lastRow = Sheets("overview").Range("G1000").End(xlUp).Row
On Error Resume Next
Application.DisplayAlerts = False
Set rRange = Application.InputBox(Prompt:="Please select a cell in the column you want
_to sort", Title:="SPECIFY COLUMN", Type:=8)
Col = rRange.Columns(1).Column
On Error GoTo 0
Application.DisplayAlerts = True
If rRange Is Nothing Then
Exit Sub
Else
If AscendingOption Then
Range("A14:CB" & lastRow).Sort key1:=Range(Col & "14:" & Col & lastRow), Order1:=xlAscending, Header:=xlNo, key2:=Range("C14:C" & lastRow), Order2:=xlAscending, Header:=xlNo
End If
If DescendingOption Then
Range("A14:CB" & lastRow).Sort key1:=Range(Col & "14:" & Col & lastRow), Order1:=xlDescending, key2:=Range("C14:C" & lastRow), Order2:=xlAscending
End If
End If
End Sub
當我點擊確定沒有任何反應:不是錯誤信息,也不是任何行動。 任何人都可以幫我找到錯誤嗎?
什麼'AscendingOption'和'DescendingOption'? – Limak
據我所知'AscendingOption'和'DescendingOption'沒有預先定義,所以如果你沒有在你的'Sub'中定義它們,它們將永遠是'False'。 –
您可能需要將'AscendingOption'和'DescendingOption'設置爲全局變量。正如Tom所說,這個變量在這個'Sub'中沒有定義。如果你想測試,在代碼的開頭添加'Option Explicit'行。當您再次運行程序時,應該會出現錯誤。 –