2012-06-28 1 views
1

VBA를 사용하여 셀 값을 확인하고 셀 값이 값 이상이면 전자 메일 모듈로 전자 메일을 보냅니다.두 개의 개인 하위 워크 시트를 결합하십시오 .Change

여러 개의 셀을 검사하지만 VBA에서 두 개의 개인 하위 Worksheet_Change를 가질 수 없다는 것을 알고 싶습니다. 여러 셀을 검사하는 가장 좋은 방법은 무엇입니까?

다음은 현재 사용중인 코드입니다.

Private Sub Worksheet_Change(ByVal Target As Range) 
    If Target.Cells.Count > 1 Then Exit Sub 
    If Not Application.Intersect(Range("A1"), Target) Is Nothing Then 
     If IsNumeric(Target.Value) And Target.Value > 10 Then 
     Call Mail_small_Text_Outlook 
     End If 
    End If 
End Sub 

여기에 나는 하나 개의 하위에 결합하고 싶습니다 가능하면 또 다른

Private Sub Worksheet_Change(ByVal Target As Range) 
    If Target.Cells.Count > 1 Then Exit Sub 
    If Not Application.Intersect(Range("B1"), Target) Is Nothing Then 
     If IsNumeric(Target.Value) And Target.Value > 20 Then 
     Call Mail_small_Text_Outlook 
     End If 
    End If 
End Sub 
+0

'If Not Application.Intersect ...'블록을 같은 Sub에 차례대로 삽입하지 않는 이유는 무엇입니까? –

답변

0

어때?

Private Sub Worksheet_Change(ByVal Target As Range) 
    Call MailAlert(Target, "A1", 10) 
    Call MailAlert(Target, "B1", 20) 
End Sub 

Private Sub MailAlert(ByVal Target As Range, ByVal Address As String, ByVal Value As Integer) 
    If Target.Cells.Count > 1 Then Exit Sub 
    If Not Application.Intersect(Range(Address), Target) Is Nothing Then 
     If IsNumeric(Target.Value) And Target.Value > Value Then 
     Call Mail_small_Text_Outlook 
     End If 
    End If 
End Sub 
+0

고마워요! 구문 오류가 발생하여 Mailalert 전에 호출을 추가해야하지만 현재 작동 중입니다. –

0
Private Sub Worksheet_Change(ByVal Target As Range) 

Select Case Taget.Address 

    Case "$A$1" 'This will make sure its just one cell and its A1   
     If IsNumeric(Target.Value) And Target.Value > 10 Then   
     Call Mail_small_Text_Outlook   
     End If  

    Case "$B$1" 'This will make sure its just one cell and its B1 
     If IsNumeric(Target.Value) And Target.Value > 20 Then   
     Call Mail_small_Text_Outlook   
     End If 

    'Case ... whatever else you want. 

End Select 
End Sub 

더 효율적인 방법이있을 수 있습니다,하지만이 먼저 마음에 온 것입니다. 희망이 귀하의 질문에 대한 답변.

관련 문제