VBA not working as expected

Russk68

Well-known Member
Joined
May 1, 2006
Messages
589
Office Version
  1. 365
Platform
  1. MacOS
Hi All,
The code below in blue text is not working. I am expecting that when I make a change anywhere in column N that formulas in AW3:AW100 and BE3:BBE1000 will calculate.


Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(R, Target) Is Nothing Then

If Target.Count > 1 Then Exit Sub
If Target.Column <> 7 Then Exit Sub
If Target <> "" And Target.Offset(0, -6) = "" Then
Target.Offset(0, -6) = "Location Needed"
ElseIf Target = "" Then
Target.Offset(0, -6).ClearContents
End If

If Not Intersect(Target, Range("N:N")) Is Nothing Then
Range("AW3:AW1000,BE3:BE1000").Calculate
End If


If Not Intersect(Target, Range("p:p,s:s,v:v,y:y")) Is Nothing Then
Range("AS1:AS1000,AT1:AT1000,AU1:AU1000,AV1:AV1000").Calculate
End If

If Not Intersect(Target, Range("h:h,ao:ao")) Is Nothing Then
Range("c1:c1000,AR1:AR1000,Be1:Bh1000").Calculate
End If

If Not Intersect(Target, Range("a:a")) Is Nothing Then
Range("d1:d1000").Calculate 'Cable color
End If

For Each Cll In Range("AO3:AO50,BP2")
For Each TCll In Target
If Cll.Address = TCll.Address Then
ThisWorkbook.Sheets("Multi Build").Calculate
ThisWorkbook.Sheets("Distro").Calculate
Exit Sub
End If
Next TCll
Next Cll
End If
End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
I'm guessing the code doesn't even get to those lines...have you stepped through the code ??
AND
As Paul has mentioned please use code tags when posting code........to do that paste your code into the post box>>highlight the code >>press the </> on the toolbar
 
Upvote 0
Hi All,
The code below in blue text is not working. I am expecting that when I make a change anywhere in column N that formulas in AW3:AW100 and BE3:BBE1000 will calculate.
Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(R, Target) Is Nothing Then If Target.Count > 1 Then Exit Sub If Target.Column <> 7 Then Exit Sub If Target <> "" And Target.Offset(0, -6) = "" Then Target.Offset(0, -6) = "Location Needed" ElseIf Target = "" Then Target.Offset(0, -6).ClearContents End If [COLOR=rgb(41, 105, 176)]If Not Intersect(Target, Range("N:N")) Is Nothing Then Range("AW3:AW1000,BE3:BE1000").Calculate End If[/COLOR] If Not Intersect(Target, Range("p:p,s:s,v:v,y:y")) Is Nothing Then Range("AS1:AS1000,AT1:AT1000,AU1:AU1000,AV1:AV1000").Calculate End If If Not Intersect(Target, Range("h:h,ao:ao")) Is Nothing Then Range("c1:c1000,AR1:AR1000,Be1:Bh1000").Calculate End If If Not Intersect(Target, Range("a:a")) Is Nothing Then Range("d1:d1000").Calculate 'Cable color End If For Each Cll In Range("AO3:AO50,BP2") For Each TCll In Target If Cll.Address = TCll.Address Then ThisWorkbook.Sheets("Multi Build").Calculate ThisWorkbook.Sheets("Distro").Calculate Exit Sub End If Next TCll Next Cll End If End Sub
 
Upvote 0
Please use code tags, it makes it much easier to read.

What is R?
I don't know what the R is for? I've been piecing this together over the years. I don't know VBA and I get help from here and Google searches.
 
Upvote 0
Sorry!
I left out some code at the top

Code:
Dim R As Range
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Set R = Selection.Cells(1, 1)
Application.Calculation = xlCalculationManual
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(R, Target) Is Nothing Then
        


If Target.Count > 1 Then Exit Sub   
If Target.Column <> 7 Then Exit Sub
If Target <> "" And Target.Offset(0, -6) = "" Then
    Target.Offset(0, -6) = "Location Needed"
ElseIf Target = "" Then
     Target.Offset(0, -6).ClearContents
End If

If Not Intersect(Target, Range("N:N")) Is Nothing Then
        Range("AW3:AW1000,BE3:BE1000").Calculate
    End If

 
    If Not Intersect(Target, Range("p:p,s:s,v:v,y:y")) Is Nothing Then 
        Range("AS1:AS1000,AT1:AT1000,AU1:AU1000,AV1:AV1000").Calculate
    End If
    
       If Not Intersect(Target, Range("h:h,ao:ao")) Is Nothing Then 
        Range("c1:c1000,AR1:AR1000,Be1:Bh1000").Calculate
       End If
       
       If Not Intersect(Target, Range("a:a")) Is Nothing Then 
        Range("d1:d1000").Calculate 'Cable color
       End If
       
      For Each Cll In Range("AO3:AO50,BP2")
        For Each TCll In Target
        If Cll.Address = TCll.Address Then
            ThisWorkbook.Sheets("Multi Build").Calculate
            ThisWorkbook.Sheets("Distro").Calculate
            Exit Sub
        End If
        Next TCll
    Next Cll
 
Upvote 0
Not sure if it's the same as PC but try these steps:

In the VBE click on the margin to the left of
Code:
If Not Intersect(R, Target) Is Nothing Then
it should be highlighted and a dot placed in the margin:

235.png

When you make a change on the worksheet the procedure will halt at that line anb be highlighted in yellow:
236.png


Press F8 to step through the code and see where it errors/exits.

PS ignore the Dim r, that was added by me!
 
Upvote 0
OK, the R is a Range!

The sub is exiting because the column number for N is 19 which does not = 7 in this line
VBA Code:
If Target.Column <> 7 Then Exit Sub

I don't know why that is there, but try commenting it out (put a ' (single quote) in front of the line) and see what happens!

'If Target.Column <> 7 Then Exit Sub
 
Upvote 0

Forum statistics

Threads
1,215,514
Messages
6,125,267
Members
449,219
Latest member
daynle

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