Is there something wrong with this VBA?

grabrail

Board Regular
Joined
Sep 6, 2010
Messages
128
Office Version
  1. 365
Platform
  1. Windows
I have some code that doesnt appear to work on my workbook

VBA Code:
Private Sub Worksheet_Change(ByVal Target2 As Range)

 If Not Intersect(Target2, Range("E121")) Is Nothing Then
        If Target2.Value < "50" Then
            Inspection.Show
           

        End If

End Sub

I would expect this to open the form, inspection if the value typed into Cell E121 is less than 50, but nothing happens


Already have a sub on the same worksheet that does similar for a different range of cells, as follows:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("E13:E27,E29:E39,J13:J35,J37:J39")) Is Nothing Then
        If Target.Value = "DF" Then
            Inspection.Show
           

        End If
       
      
    End If
End Sub
And this works fine.

Is it because i have 2 sets of code on the same sheet doing a similar task? do i need to merge the 2 pieces of code into one sub?
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
So would it be something like this? or am i getting the wrong end of the stick?

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range, ByVal target2 As Range)
    
    If Not Intersect(Target, Range("E13:E27,E29:E39,J13:J35,J37:J39")) Is Nothing Then
        
        If Target.Value = "DF" Then
            Inspection.Show
        End If
        
        If Not Intersect(target2, Range("E121")) Is Nothing Then
        
        If target2.Value < "50" Then
            Inspection.Show
        End If
End Sub
 
Upvote 0
Not quite:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Not Intersect(Target, Range("E13:E27,E29:E39,J13:J35,J37:J39")) Is Nothing Then
        
        If Target.Value = "DF" Then
            Inspection.Show
        End If
        
    ElseIf Not Intersect(target, Range("E121")) Is Nothing Then
        
        If target.Value < 50 Then
            Inspection.Show
        End If
    End If
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,874
Messages
6,122,034
Members
449,061
Latest member
TheRealJoaquin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top