Intersect - combining statements to speed processing

joey peanuts

New Member
Joined
Mar 20, 2011
Messages
18
Is there any way to combine the (2) intersect statements I am using for each named range? Even though there are only 16 of them, the code slows way down. I was using offset before, but it got confusing keeping track of the numbers. By using the named ranges, the code is easier to read. Plus, if I add or delete columns, I don't have to redo my offset values.

This is put into Private Sub Worksheet_Change(ByVal Target As Excel.Range).

Set vRange1 = Range("RBARECT_STYLE")
If Union(Target, vRange1).Address = vRange1.Address Then
If target = "" Then
Intersect(Range(Cells(Target.Row, 1), Cells(Target.Row, 100)), Range("RBARECT_HINGE")).Locked = True
Intersect(Range(Cells(Target.Row, 1), Cells(Target.Row, 100)), Range("RBARECT_HINGE")) = ""
Intersect(Range(Cells(Target.Row, 1), Cells(Target.Row, 100)), Range("RBARECT_RATIO")).Locked = True
Intersect(Range(Cells(Target.Row, 1), Cells(Target.Row, 100)), Range("RBARECT_RATIO")) = ""
Intersect(Range(Cells(Target.Row, 1), Cells(Target.Row, 100)), Range("RBARECT_WIDTH")).Locked = True
Intersect(Range(Cells(Target.Row, 1), Cells(Target.Row, 100)), Range("RBARECT_WIDTH")) = ""
Intersect(Range(Cells(Target.Row, 1), Cells(Target.Row, 100)), Range("RBARECT_HEIGHT")).Locked = True
Intersect(Range(Cells(Target.Row, 1), Cells(Target.Row, 100)), Range("RBARECT_HEIGHT")) = ""
Intersect(Range(Cells(Target.Row, 1), Cells(Target.Row, 100)), Range("RBARECT_OPER")).Locked = True
Intersect(Range(Cells(Target.Row, 1), Cells(Target.Row, 100)), Range("RBARECT_OPER")) = ""
Intersect(Range(Cells(Target.Row, 1), Cells(Target.Row, 100)), Range("RBARECT_TEMP")).Locked = True
Intersect(Range(Cells(Target.Row, 1), Cells(Target.Row, 100)), Range("RBARECT_TEMP")) = ""
Intersect(Range(Cells(Target.Row, 1), Cells(Target.Row, 100)), Range("RBARECT_OBSPATT")).Locked = True
Intersect(Range(Cells(Target.Row, 1), Cells(Target.Row, 100)), Range("RBARECT_OBSPATT")) = ""
Intersect(Range(Cells(Target.Row, 1), Cells(Target.Row, 100)), Range("RBARECT_SCREEN")).Locked = True
Intersect(Range(Cells(Target.Row, 1), Cells(Target.Row, 100)), Range("RBARECT_SCREEN")) = ""
End if
End if

Thank you!
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Maybe ...
Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    If Union(Target, Range("RBARECT_STYLE")).Address = Range("RBARECT_STYLE").Address Then
        If IsEmpty(Target.Value) Then
            With Intersect(Cells(Target.Row, 1).Resize(, 100), _
                           Range("RBARECT_HINGE, RBARECT_RATIO, RBARECT_WIDTH, " & _
                                 "RBARECT_HEIGHT, RBARECT_OPER, RBARECT_TEMP, " & _
                                 "RBARECT_OBSPATT, RBARECT_SCREEN"))
                .Locked = True
                .ClearContents
            End With
        End If
    End If
End Sub
 
Upvote 0
Maybe ...
Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    If Union(Target, Range("RBARECT_STYLE")).Address = Range("RBARECT_STYLE").Address Then
        If IsEmpty(Target.Value) Then
            With Intersect(Cells(Target.Row, 1).Resize(, 100), _
                           Range("RBARECT_HINGE, RBARECT_RATIO, RBARECT_WIDTH, " & _
                                 "RBARECT_HEIGHT, RBARECT_OPER, RBARECT_TEMP, " & _
                                 "RBARECT_OBSPATT, RBARECT_SCREEN"))
                .Locked = True
                .ClearContents
            End With
        End If
    End If
End Sub


Thank you - I'll give that a try.
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,299
Members
452,904
Latest member
CodeMasterX

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