我使用以下代码让用户选择他们想要编辑的单元格。
Application.InputBox(Prompt:="Click the cell you want to edit.", Title:="Cell To Edit", Type:=8)
如何更改我的代码,以便他们一次只能选择一个单元格?
答案 0 :(得分:1)
这是你在尝试的吗?
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
答案 1 :(得分:0)
怎么样:
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