简体   繁体   English

根据其他2个单元格的值将excel单元格设置为强制性

[英]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: 这是A1B1C1的示例,在工作表代码区域中输入以下事件宏:

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: 因为它是工作表代码,所以非常易于安装和自动使用:

  1. right-click the tab name near the bottom of the Excel window 右键单击Excel窗口底部附近的选项卡名称
  2. select View Code - this brings up a VBE window 选择查看代码-这将打开一个VBE窗口
  3. paste the stuff in and close the VBE window 将内容粘贴并关闭VBE窗口

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: 删除宏:

  1. bring up the VBE windows as above 如上调出VBE窗口
  2. clear the code out 清除代码
  3. close the VBE window 关闭VBE窗口

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.

相关问题 基于Excel中其他单元格值组合的单元格返回值 - Return value in cell based on other cells values combination in excel Excel根据其他单元格值创建“条形”或填充一系列单元格 - Excel create “bars” or fill series of cells based on other cell value Excel VBA颜色单元格基于其他两个单元格中的值 - Excel VBA color cell based on value in two other cells 如何强制使用excel单元格? - How to make excel cells mandatory? Excel,根据第一个单元格的值将一个单元格拆分为其他特定的单元格 - Excel, split one cell into other specific cells based on the value from the first cell 根据Excel中的4个单元格值更改单元格颜色 - Change the Cell Color based on 4 Cells value in Excel excel-根据第一个单元格中的数字将单元格数据拆分为其他单元格 - excel - Splitting cell data into other cells based on a number in the first cell 尝试在 excel 中创建一个宏,该宏根据行中其他单元格的值控制单元格的输出 - Attempt to create a macro in excel that controls the out put of a cell based on the value of other cells in the row 根据其他单元格中的值显示一个或多个单元格的值 - Displaying value of one cell or multiple cells based on values in other cells Excel VBA / Formula用于基于其他2个单元格的值填充3个特定单元格 - Excel VBA/Formula for populating 3 specific cells based on the value of 2 other cells
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM