VBA Loop problem

MrHuge

Board Regular
Joined
Jun 23, 2005
Messages
219
Hi, i have the following code

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Intersect(Target, Range("FilterClient")) Is Nothing Then GoTo FilterProject

        'Range("FilterProject").Clear
        'Run "InsertRow"
        
        Exit Sub
        
FilterProject:

    If Intersect(Target, Range("FilterProject")) Is Nothing Then GoTo theend

        'Range("FilterClient").Clear
        'Run "InsertRow"
        Exit Sub
        
theend:

End Sub
What i am trying to do is delete the other cells contents when something is entered into the other cell, but it gets stuck in a loop, any suggestions would be fantastic.
 

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
Hi,

To avoid an endless loop it's necessary to disable the events.

I dont know what your macro InsertRow does, so maybe something like this (try it on a copy of your workbook)

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 
    If Not Intersect(Target, Range("FilterClient")) Is Nothing Then
        Application.EnableEvents = False
        Range("FilterProject").Clear
        Application.Run "InsertRow"
        Application.EnableEvents = True
        Exit Sub
    End If
 
    If Not Intersect(Target, Range("FilterProject")) Is Nothing Then
        Application.EnableEvents = False
        Range("FilterClient").Clear
        Application.Run "InsertRow"
        Application.EnableEvents = True
    End If
 
End Sub

M.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,513
Messages
6,179,214
Members
452,895
Latest member
BILLING GUY

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