[英]Make an excel cell mandatory, based on value of other 2 cells
So.. I've an excel where 2 consecutive cells can be marked with the same value (mostly Text), based on this 2 cells the value of the 3rd cell should be filled mandatorily by the user. 所以..我有一个擅长的地方,可以用相同的值(主要是文本)标记2个连续的单元格,基于这2个单元格,用户必须强制填充第3个单元格的值。
The range of cells can be different as I need to use the same snippet cross many excels. 单元格的范围可以不同,因为我需要使用许多优秀的相同代码段。
Any help would be sincerely appreciated. 任何帮助将由衷的感谢。
Many thanks! 非常感谢! :)
:)
There's more then one way to skin a cat, but probably the easiest way to do it would be to include a vba sub which (on some trigger, like submitting) checks the value of cell 1 and 2 and IF that value is whatever you want to trigger on... if cell 3 is blank prompt the user to fill in box three. 有一种以上的方法可以给猫剥皮,但最简单的方法可能是包括一个vba sub,该vba sub(在某些触发条件下,例如提交)检查单元格1和2的值,如果该值是您想要的值触发...如果单元格3为空白,则提示用户填写框3。
IF Range("A1").Value == "Trigger" And Range("A2").Value == "Trigger" And Range("A3") == "" Then msgBox("You must fill in cell A3")
If you add a break statement like End Sub, the sheet can't continue until that cell is filled. 如果添加诸如End Sub之类的break语句,则在填充该单元格之前,图纸无法继续。
This is an example for A1 , B1 , C1 enter the following event macro in the worksheet code area: 这是A1 , B1 , C1的示例,在工作表代码区域中输入以下事件宏:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim A As Range, B As Range, C As Range
Set A = Range("A1")
Set B = Range("B1")
Set C = Range("C1")
If A <> "" And B <> "" And C = "" Then
Application.EnableEvents = False
C.Select
Application.EnableEvents = True
MsgBox "please enter a value in cell C1"
End If
End Sub
Because it is worksheet code, it is very easy to install and automatic to use: 因为它是工作表代码,所以非常易于安装和自动使用:
If you have any concerns, first try it on a trial worksheet. 如果您有任何疑问,请先在试用版工作表上尝试一下。
If you save the workbook, the macro will be saved with it. 如果您保存工作簿,则宏将随其一起保存。 If you are using a version of Excel later then 2003, you must save the file as .xlsm rather than .xlsx
如果您在2003年以后使用Excel版本,则必须将文件另存为.xlsm而不是.xlsx
To remove the macro: 删除宏:
To learn more about macros in general, see: 要总体上了解有关宏的更多信息,请参见:
http://www.mvps.org/dmcritchie/excel/getstarted.htm http://www.mvps.org/dmcritchie/excel/getstarted.htm
and 和
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx http://msdn.microsoft.com/zh-CN/library/ee814735(v=office.14).aspx
To learn more about Event Macros (worksheet code), see: 要了解有关事件宏(工作表代码)的更多信息,请参见:
http://www.mvps.org/dmcritchie/excel/event.htm http://www.mvps.org/dmcritchie/excel/event.htm
Macros must be enabled for this to work! 必须启用宏才能使其正常工作!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.