2017-02-23 75 views
0

這裏VBA的Excel代碼是我的代碼,我試圖運行: -擦除一系列錯誤

Sub EraseRange() 
Dim UserRange As Range 

Set UserRange = Application.InputBox(_ 
    "Range to Erase", _ 
    "Range Erase", _ 
    Selection.Address, _ 
    8) 

UserRange.Clear 
UserRange.Select 
End Sub 

它提高運行時錯誤: ****運行時錯誤「424」 必選對象* ***

回答

0

替換您行:

Set UserRange = Application.InputBox(_ 
    "Range to Erase", _ 
    "Range Erase", _ 
    Selection.Address, _ 
    8) 

有了:

Set UserRange = Application.InputBox(Prompt:="Range to Erase", _ 
    Title:="Range Erase", Type:=8) 

注:很少有使用UserRange.Select,一旦你已經通過InputBox

+0

由於選擇了它。有效。你能告訴我問題是什麼嗎? –

+0

@HimanshuSingh當'Application.InputBox'與'Type:= 8'一起使用時,您不需要第三個參數'Selection.Address',它已經聲明您希望獲得'Range'作爲輸入。無論如何,'Selection.Address'返回一個'String'而不是'Range' –