2017-08-09 83 views
0
Sub Clear_Table(ct) 
    Range(ct).Select 
    'Range(Selection, Selection.End(xlToRight)).Select 
    'Range(Selection, Selection.End(xlDown)).Select 
    Selection.ClearContents 
    Range(ct).Select 
End Sub 

Sub rite() 



Clear_Table ("E10") 

Range("E10").Value = "dwsds" 

End Sub 

getting compile error: Argument not optional (only want to clear value in a cell not the entire range and put the value in that cell. please help)我要清除一個單元格,然後將值賦給它

+0

同意Vityata的觀點,但我不能複製你的錯誤。也許你有其他的代碼。 – SJR

回答

1

下面是一些可以做的工作:

Option Explicit 

Sub Clear_Table(ct As Range) 

    ct.ClearContents 

End Sub 

Sub rite() 

    Clear_Table Range("E10") 
    Range("E10").Value = "dwsds" 

End Sub 

儘量避免選擇儘可能多的,你可以。在這裏看到更多 - How to avoid using Select in Excel VBA

+0

謝謝@vityata –

+0

歡迎,@DaulatDaga :)隨時接受答案,一旦你可以:) – Vityata

相關問題