防止用户select多个单元格

我正在使用下面的代码让用户select他们想要编辑的单元格。

Application.InputBox(Prompt:="Click the cell you want to edit.", Title:="Cell To Edit", Type:=8) 

我怎样才能改变我的代码,所以他们一次只能select一个单元格?

这是你正在尝试?

 Sub Sample() Dim r As Range Do On Error Resume Next Set r = Application.InputBox(Prompt:="Click the single cell you want to edit.", _ Title:="Cell To Edit", _ Type:=8) On Error GoTo 0 If r Is Nothing Then Exit Sub If r.Cells.Count = 1 Then Exit Do Else MsgBox "Please select a single cell only" Set r = Nothing End If Loop 'MsgBox r.Address End Sub 

怎么样:

 Sub qwerty() Dim r As Range Set r = Range("A1:A2") While r.Count <> 1 Set r = Application.InputBox(Prompt:="Click the cell you want to edit.", Title:="Cell To Edit", Type:=8) Wend End Sub