单元格更改时提示用户

一般来说,我对创buildmacros和编程非常新。 我有一个38选项卡的工作表。 每个月的日子有31个标签。 我想创build一个macros,在任何时候都会提示用户发出警告消息,在N列中为这31个选项卡中的每一个select“MCO”。 那可能吗?

谢谢

这是可能的,使用工作簿级别SheetSelectionChange事件。 在VBA项目的ThisWorkbook模块中粘贴以下代码:

Option Compare Text Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range) Dim SelectedCellsInColN As Range ' Make a range of the cells in Target range that intersect with the cells in the N column Set SelectedCellsInColN = Intersect(Target, Target.Parent.Range("N1:N" & CStr(Target.Parent.Rows.Count))) If Not SelectedCellsInColN Is Nothing Then ' The user has selected a cell in column N Dim CurrCell As Range For Each CurrCell In SelectedCellsInColN ' If the cell's value contains mco (in any case) then prompt the user with a messagebox If CurrCell.Value Like "*MCO*" Then MsgBox "You've selected MCO" ' Exit the sub so we don't keep bugging the user about it... Exit Sub End If Next CurrCell End If End Sub 

基本上,代码所做的就是查看目标范围,看是否选中了N列中的任何单元格,然后遍历列N中所有选中的单元格,以查看它们的值是否包含MCO(可以删除如果您只想在单元格中包含“MCO”时提示,则提示用户并退出。

希望有所帮助。

-Jon

你正在寻找一个macros观解决scheme或vba解决scheme。 两者是不同的。 对于macros运行使用macros编码器的步骤,对于VBA解决scheme开始Jon的答案