WorkSheet_Change事件不允许更改多个单元格 [英] WorkSheet_Change event does not allow to change more than one cell

查看:524
本文介绍了WorkSheet_Change事件不允许更改多个单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在使用worksheet_change事件进行VBA练习,我试图在excel中更改多个单元格以便应触发Change事件.但是问题是,当我更改单个单元格时,Change事件被触发了,不允许更改多个单元格.我想更改多个单元格,以便应触发更改事件.任何人都可以引导我解决此问题.


还是要获取更改后的单元格值?


谢谢.

Hi Everybody,

I am working in VBA exercise using worksheet_change event,I was trying to change multiple cells in excel so that Change event should fire.But issue is, when I change single cell Change event gets fired ,not allowing to change multiple cells.I want to change multiple cells so that change event should fire.Can anyone plz guide me to solve this.
or

Anyotherway for getting changed cell value?


Thank You.

推荐答案

您可以指定列或行之类的范围,以便一旦这些单元格集可以激活您想要的代码
you can specify the ranges like the column or row so that once those set of cells can active the code you desire
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    If Target.Column = 1 Then
        ThisRow = Target.Row
        If Target.Value > 100 Then
            Range("B" & ThisRow).Interior.ColorIndex = 3
        Else
            Range("B" & ThisRow).Interior.ColorIndex = xlColorIndexNone
        End If
    End If
End Sub


希望对您有帮助


hope this helps


Target参数是一个范围对象,它可以覆盖多个单元格.要从不同的单元格检索值:

Public Sub worksheet_change(ByVal目标为Excel.Range)

Dim celCurr作为Excel.Range

对于target.Cells中的每个celCurr
Debug.Print celCurr.Address,celCurr.value
下一个celCurr

设置celCurr = Nothing

结束Sub
The Target parameter is a range object, it can cover multiple cells. To retrieve the values from the different cells:

Public Sub worksheet_change(ByVal target As Excel.Range)

Dim celCurr As Excel.Range

For Each celCurr In target.Cells
Debug.Print celCurr.Address, celCurr.value
Next celCurr

Set celCurr = Nothing

End Sub


这篇关于WorkSheet_Change事件不允许更改多个单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆