防止用户选择多个单元格 [英] Prevent users from selecting multiple cell

查看:127
本文介绍了防止用户选择多个单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码让用户选择要编辑的单元格。

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?

推荐答案

这是你正在尝试的吗?

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

这篇关于防止用户选择多个单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆