更改数据验证保管箱上的值后运行宏

时间:2015-04-08 05:45:16

标签: excel-vba vba excel

一个好人帮我创建了以下代码,当你在B列下的任何单元格上手动输入一个值但是当我从数据验证中选择值时,我尝试使用相同的代码时,它工作正常,我需要改变什么吗?

Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Columns("B")) Is Nothing Then
        On Error GoTo Safe_Exit
        Application.EnableEvents = False
        Dim rng As Range
        For Each rng In Intersect(Target, Columns("B"))
            If rng.Row > 2 Then ' your sample code seemed to suggest that this should start on row 3 and higher
                Call Settime(rng.Row)
            End If
        Next rng
    End If
Safe_Exit:
    Application.EnableEvents = True
End Sub

Sub Settime(rw as long)
    If range("B" & rw) = "" Then
        MsgBox "Ingrese El account Number" 
    Else
        Range("J" & rw & ":K" & rw) = Range("J" & rw & ":K" & rw).value
    End If 
End Sub

0 个答案:

没有答案