Cancel A vba Code

IoanZ

Board Regular
Joined
Mar 2, 2018
Messages
51
Hello

In active sheet I use this VBA code to insert new rows just by double clicking mouse button.

The Code: ///

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Updateby Extendoffice 20160725
Application.ScreenUpdating = False
Cancel = True
If Intersect(Target, [C224:C424]) Is Nothing Then Exit Sub
Target.Offset(1).EntireRow.Insert
Target.EntireRow.Copy Target.Offset(1).EntireRow
On Error Resume Next
Target.Offset(1).EntireRow.SpecialCells(xlConstants).ClearContents
Application.ScreenUpdating = True
End Sub ///

I want to interrupted this VBA code when in active sheet Cell C4 has value TRUE for example


Thanks
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
This seems to do it:

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

Application.ScreenUpdating = False
Cancel = True
    If UCase(ActiveSheet.Range("C4").Value) = "TRUE" Then Exit Sub
    If Intersect(Target, [C224:C424]) Is Nothing Then Exit Sub
        Target.Offset(1).EntireRow.Insert
        Target.EntireRow.Copy Target.Offset(1).EntireRow
    On Error Resume Next
        Target.Offset(1).EntireRow.SpecialCells(xlConstants).ClearContents
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Try this:
Script will not run if C4 equals "No"
Using True is not a good way.

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Modified 6/29/18 10:10 AM EDT
Application.ScreenUpdating = False
Cancel = True
If Range("C4").Value = "No" Then Exit Sub
If Intersect(Target, [C224:C424]) Is Nothing Then Exit Sub
Target.Offset(1).EntireRow.Insert
Target.EntireRow.Copy Target.Offset(1).EntireRow
On Error Resume Next
Target.Offset(1).EntireRow.SpecialCells(xlConstants).ClearContents
MsgBox "Done"
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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