Trying to run a worksheet change event twice

前端 未结 2 337
甜味超标
甜味超标 2021-01-22 15:39

I am trying to run this worksheet change event for two different columns(A) and (I)...

    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim A As R         


        
2条回答
  •  情歌与酒
    2021-01-22 16:23

    Just expand the range you set to the A variable.

    Set A = Range("A:A, I:I")
    

    Rewritten as,

    Private Sub Worksheet_Change(ByVal Target As Range)
        if not intersect(range("A:A, I:I"), target) is nothing then
            'add error control
            on error goto safe_exit
            'don't do anything until you know something has to be done
            dim r as range
            Application.EnableEvents = False
            For Each r In intersect(range("A:A, I:I"), target)
                r.Offset(0, 1).Value = Date   'do you want Date or Now?
            Next r
        end if
    safe_exit:
        Application.EnableEvents = True 
    End Sub
    

提交回复
热议问题