我正在處理用戶可以輸入範圍的Excel用戶表單。例如,他們可以放入「B5」和「B20」。範圍對象的Excel錯誤處理
我試圖做錯誤處理,以防止用戶輸入錯誤的範圍。例如,「asdf」和「fdsa」。
下面的代碼失敗:
Private Sub cmdSend_Click()
Dim beginTerm As String
Dim endTerm As String
beginTerm = TermsBegin.Text
endTerm = TermsEnd.Text
If (IsError(Worksheets("Account Information").Range(beginTerm + ":" + endTerm)) = True) Then
MsgBox "Cell Range is invalid."
Exit Sub
End If
End Sub
我也試過如下:
Private Sub cmdSend_Click()
Dim beginTerm As String
Dim endTerm As String
beginTerm = TermsBegin.Text
endTerm = TermsEnd.Text
Dim myRange As Range
myRange = Worksheets("Account Information").Range(beginTerm + ":" + endTerm)
On Error GoTo ErrHandler
On Error GoTo 0
'other code ...
ErrHandler:
MsgBox "Cell Range is invalid."
Exit Sub
End Sub
我的問題是如何處理它失敗的情況下?
謝謝!
也許只是使用RefEdit控件呢? –