Excel VBA 问题. change event
大侠,我需要在sheet1里做两个changeevent.1.如果D列有改变,E列就响应变化,2.如果F列有改变,G列就相应变化.我不太知道怎么组合这两个changeev...
大侠, 我需要在sheet1里做两个change event. 1. 如果D列有改变,E列就响应变化, 2. 如果F列有改变, G列就相应变化. 我不太知道怎么组合这两 个change event, 下面的代码不起作用. 请指教!!!!
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Range("D1:D50"), Range(Target.Address)) Is Nothing Then
Call change_screen
Else
If Not Application.Intersect(Range("F1:F50"), Range(Target.Address)) Is Nothing Then
Call change_screen2
End If
End If
End Sub
Sub change_screen()
Dim x As Integer
For x = 1 To 50
If Sheets("Sheet1").Range("D" & x).Value = "No" Then
Sheets("Sheet1").Range("E" & x).Value = "2"
Else
If Sheets("Sheet1").Range("D" & x).Value = "Yes" Then
Sheets("Sheet1").Range("E" & x).Value = "3"
Else
Sheets("Sheet1").Range("E" & x).Value = ""
End If
End If
Next x
End Sub
Sub change_screen2()
Dim x As Integer
For x = 1 To 50
If Sheets("Sheet1").Range("F" & x).Value = "No" Then
Sheets("Sheet1").Range("G" & x).Value = "2"
Else
If Sheets("Sheet1").Range("F" & x).Value = "Yes" Then
Sheets("Sheet1").Range("G" & x).Value = "3"
Else
Sheets("Sheet1").Range("F" & x).Value = ""
End If
End If
Next x
End Sub 展开
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Range("D1:D50"), Range(Target.Address)) Is Nothing Then
Call change_screen
Else
If Not Application.Intersect(Range("F1:F50"), Range(Target.Address)) Is Nothing Then
Call change_screen2
End If
End If
End Sub
Sub change_screen()
Dim x As Integer
For x = 1 To 50
If Sheets("Sheet1").Range("D" & x).Value = "No" Then
Sheets("Sheet1").Range("E" & x).Value = "2"
Else
If Sheets("Sheet1").Range("D" & x).Value = "Yes" Then
Sheets("Sheet1").Range("E" & x).Value = "3"
Else
Sheets("Sheet1").Range("E" & x).Value = ""
End If
End If
Next x
End Sub
Sub change_screen2()
Dim x As Integer
For x = 1 To 50
If Sheets("Sheet1").Range("F" & x).Value = "No" Then
Sheets("Sheet1").Range("G" & x).Value = "2"
Else
If Sheets("Sheet1").Range("F" & x).Value = "Yes" Then
Sheets("Sheet1").Range("G" & x).Value = "3"
Else
Sheets("Sheet1").Range("F" & x).Value = ""
End If
End If
Next x
End Sub 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询