Executes Continuously

Rubber Beaked Woodpecker

Board Regular
Joined
Aug 30, 2015
Messages
203
Office Version
  1. 2021
What adjustment do I need to make please so that the following code only executes the once? As it is it is in a never ending loop :mad:

VBA Code:
Option Explicit

Dim currentMarket As String

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Columns.Count = 16 Then
    Application.EnableEvents = False
     If Range("R1").Value = 6 Then
            logBalance
   End If
    End If
    Application.EnableEvents = True
End Sub
 
Last edited:

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
never ending loop, every second, every minute, easy, you can do with an application.ontime
do you want with an interval less then 1 sec ??
How often ?
 
Upvote 0
normally something you don't want, an endless loop, how do you stop that one.
Add a doevents, in case you want to break the macro.
Use a pointer if you want to stop after 1e15 loops (or reset that just before)

Sorry, but i can't see the advantage with an event-macro for the change of range ("R1") ...
Your processor is busy doing nothing ...

VBA Code:
Option Explicit

Dim currentMarket As String

Private Sub Worksheet_Change(ByVal Target As Range)
     Dim ptr   As Double
     If Target.Columns.Count = 16 Then
          Application.EnableEvents = False
          Do                                                    'this loop is almost endless
               DoEvents                                         'try to stop your macro
               ptr = ptr + 1
               If Range("R1").Value = 6 Then
                    logBalance
               End If
               If ptr >= 1E+15 Then ptr = 0
          Loop While ptr < 1E+15                                'stop at pointer>=1e
     End If
     Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,119
Messages
6,128,946
Members
449,480
Latest member
yesitisasport

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