Tim
Tim

Reputation: 111

Prevent users from selecting multiple cell

I am using the following code to let users select the cell they want to edit.

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

How can I change my code so they can only select one cell at a time?

Upvotes: 1

Views: 1206

Answers (2)

Siddharth Rout
Siddharth Rout

Reputation: 149305

Is this what you are trying?

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

Upvotes: 1

Gary's Student
Gary's Student

Reputation: 96753

How about:

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

Upvotes: 0

Related Questions