允许用户input一个单元格(三个单元格中的任何一个)
我正在寻找在Excel中的检查,从而如果用户input三个单元格中的一个值,则剩下的两个单元格不应该允许数据input。 我已经看过数据validation,但找不到我在找什么。 谢谢你帮助我。
这是使用单元格A1,B1和C1的示例。
将下面的事件macros放在工作表代码区域中:
Private Sub Worksheet_Change(ByVal Target As Range) Dim rLook As Range Set rLook = Range("A1:C1") Dim wf As WorksheetFunction Set wf = Application.WorksheetFunction If Intersect(Target, rLook) Is Nothing Then Exit Sub If wf.CountA(rLook) < 2 Then Exit Sub Application.EnableEvents = False Target.Clear MsgBox "Only one entry allowed" Application.EnableEvents = True End Sub
因为它是工作表代码,所以安装和自动使用非常简单:
- 右键单击Excel窗口底部附近的选项卡名称
- select查看代码 – 这会popup一个VBE窗口
- 粘贴东西,closuresVBE窗口
如果您有任何疑问,请先在试用工作表上尝试。
如果您保存该工作簿,该macros将与它一起保存。 如果您在2003年以后使用的是Excel版本,则必须将该文件另存为.xlsm而不是.xlsx
要删除macros:
- 调出上面的VBE窗口
- 清除代码
- closuresVBE窗口
要了解有关macros的更多信息,请参阅:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
和
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
要了解有关事件macros(工作表代码)的更多信息,请参阅:
http://www.mvps.org/dmcritchie/excel/event.htm
macros必须启用这个工作 !