Cell Value Change Event and Running a Continuous Macro

纵然是瞬间 提交于 2019-12-04 15:29:23
Gary's Student

You can use a worksheet event macro:

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rB As Range
    Set rB = Range("B:B").Cells.SpecialCells(xlCellTypeAllValidation)
    If Intersect(Target, rB) Is Nothing Then
    Else
        Application.EnableEvents = False
            Call Update
        Application.EnableEvents = True
    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
  2. select View Code - this brings up a VBE window
  3. paste the stuff in and close the VBE window

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

To remove the macro:

  1. bring up the VBE windows as above
  2. clear the code out
  3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

and

http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm

Macros must be enabled for this to work!

Jacob Lambert

What you are going to need is a Worksheet_Changed event similar to this:

Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Column("B")) Is Nothing Then
        Application.EnableEvents = False
        Call Update
        Application.EnableEvents = True
    End If
End Sub

This will trigger if any changes are made in column B. The Target is supplied by the application event and is the range that had the change made.

Edit: You will need to put this in the code of the sheet, not a module. If you right click on the sheet tab at the bottom of the excel screen, one of the options is view code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!