Stopping An Endless Loop
Dec 21, 2006
I have the following VBA in the attatched spreadsheet (seperated so I could upload)
The only problem that I have is that I cannot stop the loop, it constantly keeps going round in a circle.
What im wanting to do is when the Date checked is the End date and the End Time has been checked, to move onto the next row and do it again until it gets to row 40.
Sub Calculate()
Dim CellNo As Integer
Dim CurrentDate As Date
Dim StartDate As Date
Dim EndDate As Date
Dim theDate As String
Dim c As Range
Dim i As Integer
Dim addDate As Integer
Dim DaysHoursSick As Date
Dim StartWorkTime As Date
Dim EndWorkTime As Date
Dim endmarker As String
I've only got this VBA working really under Wednesday so I can make sure it is right before adding it onto the other dates,
View 4 Replies
ADVERTISEMENT
May 16, 2007
Why does my Excel hang on this
While TempWaarde1 <> ""
TempWaarde1 = Cells.Value(Posi, 1)
TempWaarde2 = Cells.Value(Posi - 1, 1)
If TempWaarde1 <> TempWaarde2 Then
ListBox1.AddItem TempWaarde1
End If
Posi = Posi + 1
Wend
What I'm trying to achief is to fill a listbox with all values in the first column of the active sheet, but avoiding double entry's if they're on the row after the 1st one. When I execute this in my Userform_Initialize, Excel hangs like the while-wend loop is never finishing, while i'm sure there is no more data in the 1st column after 200 rows or so.
View 3 Replies
View Related
Apr 27, 2009
I've used a loop in one of my macros and the loop goes on endlessly. I've been trying to come up witha way to overcome this problem but with no luck till now. knowing that I'm new to VBA i decided to turn to the big guns at mr.exxcel to help me out. Here's the code i have. Any alternatives to this would be VERY VERY VERY USEFUL!!!
Sub smalloops()
Dim i As Integer
Dim compliant As Integer
Dim noncompliant As Integer
compliant = 0
noncompliant = 0
For i = 1 To 60
Do Until Cells(i, 2) = ("RECOMMENDATIONS")
Do While Cells(i, 3) 0
If Cells(i, 7) = 1 Then
compliant = compliant + 1
ElseIf Cells(i, 7) = 2 Then.................
View 9 Replies
View Related
Jun 15, 2009
Having another problem with the same macro that has been giving me trouble for a week now. Now, the macro will run, but after it finishes, excel stops responding. Is this because the macro continues to run indefinitely.
View 3 Replies
View Related
Oct 25, 2011
I have a multi-sheet workbook. The first sheet is a summary of results from the rest of the workbook. I would like this summary sheet to auto-refresh itself each time the sheet is activated. The VBA code triggered by the Worksheet/Activate event feeds some parameters out to other sheets, then copies back the results to the summary sheet of the workbook.
While doing so, it keeps "reactivating" the first sheet, causing it to get into an endless loop that is triggered by the Worksheet/Activate event. Essentially, I'd like the Worksheet/Activate event to go dormant for 15 seconds or so each time it is triggered.
View 3 Replies
View Related
May 14, 2014
I have a very long routine, looping through 35,000-ish rows several times to detect and delete unwanted items. Occasionally, it gets locked into an endless loop and CTRL+Break will not stop it - I have to kill Excel through the Task Manager.
How can I find out where the endless loop is so I can detect what's causingit and fix it?
View 6 Replies
View Related
Aug 6, 2008
When I set a "for each cell in range" to go through the range, and if there are merged cells in this range, this will result an endless loop.
View 9 Replies
View Related
Oct 28, 2006
I have loops working in other loops. The macro is almsot working well. It does the calculation i want but it fails to stop a loop, because of that, the macro can't run the next main loop (c), which is to move to the next cell where the calculations must be run.
I attach a file. the troubleshooting macroation is Sub Itiration.
The code of this macro are bellow. Basically, the loop using d as counter run into an endless loop. I don't how to stop this loop without affecting the results which are calculated correctly.
Sub Itiration()
Dim CurCell As Object
Dim TempSum As Double
Dim d As Integer
For c = 3 To Cells(3, 4)
If Cells(11, c) > 0 Then
For i = 1 To Cells(10, c)
Do
View 9 Replies
View Related
Jul 12, 2006
how to quit this Do and For loop:
This simple coding should repeat this four times:
first ask user to input data in Textbox2.Text and then Textbox3.Text until user presses Cancel. --> x 4
But it don't seem to exit the Do Loop
For j = 1 To 4
i = 1
Data1 = TextBox2.Text
Cells(i, j).Value = Data1
Do
n2 = TextBox3.Text
If Cells(i, j).Value <> "" Then
Do
i = i + 1
Loop Until Cells(i, j).Value = ""
End If
View 7 Replies
View Related
Oct 4, 2009
I have written the macro;
Sub
For i = 2 To FinalRow
If Cells(i, 1).Value = Range("A1") Then
Cells(i, 1).Select
End If
Next i
End Sub
And I was wondering if there was a way to end the Sub as soon as it gets to the Cell with the “A1” value in it as opposed to just continuing through all the rows to the end of the sheet even after the right value has been found?
View 9 Replies
View Related
Jan 21, 2012
I've modified some code to perform a loop which creates a new worksheet for each item in a pivot table Page By field (EmpName), copying and pasting values for the displayed pivot table with each name selected. Everything is working fine until it gets done with the last item in the list, at which point I get a Run Time Error 1004, "Unable to Get Properties of the Worksheet Class".
I want the MsgBox to pop up at the end, stating how many sheets have been added.
Sub Loop_PivotItems()
'Turn off screen updating
Application.ScreenUpdating = False
'Store the sheet with the Pivot Table
Piv_Sht = ActiveSheet.Name
'Loop through every PivotItem in the PageField (Filter) of the Pivot Table
[Code] ...........
View 2 Replies
View Related
Aug 8, 2007
I have some code which, which I have modified it to create check boxes for all rows of data, but when I run it, it begins to wipe out the data, and create an endless column of numbers and check boxes. Here is the code:
Sub SelectCell()
Application. ScreenUpdating = False
Dim Z As Range
Set Z = Cells(1, 1).EntireColumn. Find("*", SearchDirection:=xlPrevious)
For i = 2 To Z
Range("A" & i) = i
Set cll = Range("A" & i).Offset(0, 1)
For Each shp In ActiveSheet.Shapes
If Left(shp.Name, 8) = "CheckBox" And shp.TopLeftCell.Address = cll.Address Then
shp.Delete
Exit For.......................
I have tried to set it to recognize how many rows are filled with number, give that to variable Z and then apply the code but it simply does not work.
View 7 Replies
View Related
Mar 22, 2007
In my main macro I have a line that makes it jump into a timer subroutine that starts the main macro every 30 seconds. However, I also have a line in the main macro that makes it jump into another subroutine at 2pm everyday that sends out emails. The problem is that if the timer starts the main macro again before the sending emails subroutine finishes, then it will only finish sending a portion of the emails before it jumps back into the main macro. Is there any way to stop my main macro once it recognizes that it needs to jump into the email sending subroutine, or a way to at least stop the timer subroutine?
the part of my code the jump into the sending emails subroutine and the timer subroutine look like this so far:
If timevalue(now()) >= timevalue("14:00:00") And timevalue(now()) < timevalue("14:00:31") _
Then DAILY_REPORT
End If
StartTimer
View 4 Replies
View Related
Jan 8, 2009
A good number of years ago I used a line of code at the beginning and the end of a macro to keep the spreadsheet from moving until the macro was finished. At the close it moved if a movement was necessary.
View 6 Replies
View Related
Oct 4, 2011
how do i stop a sheet from being printed and add an error message/ dialogue box saying this sheet cannot be printed, view only etc etc. this to appear when they goto the print option in the menus.
View 5 Replies
View Related
Aug 24, 2012
I have a for which consists of
2textbox
1 listbox
1 textbox.
While entering the data, the cursor does not stop in the list box and goes directly goes to the next textbox. Autotab is set to true.
View 4 Replies
View Related
Jul 20, 2014
I am using a code to transfer data from one sheet to another using the VBA below. The only problem I am having is it is copying the conditional formatting as well which I don't want it to do as it is already set up in the sheet it is copying to. How can I stop this?
Code:
Sub MONTHLY_UPDATE_TextBox2_Click()Dim rRehab As Long, i As Long
Dim wsRehab As Worksheet
Set wsRehab = Worksheets("AUG")
[Code]....
View 3 Replies
View Related
Dec 21, 2007
I have event procedures for the following form events: Before update, After Update, On Open, On Load and On Activate and I have added a breakpoint to every event.
However, despite breakpoints in all these pieces of code the form opens and closes without the code stopping to allow me to debug by manually stepping through the code.
Have I done something fundamentally wrong, I'm still a newbie at VBA?
View 9 Replies
View Related
Nov 3, 2006
I am running a timer in XL using the Application .OnTime Method.
Everywhere I've looked tells me that the procedure to stop the timer is
Sub StopTimer()
On Error Resume Next
Application.OnTime earliesttime:=RunWhen, procedure:=cRunWhat, schedule:=False
End Sub
I have this code in with the timer, but when I hit F5 or go to Tools--->Macros--> and Run the StopTimer Macro the timer just keeps running.
how I can properly call this procedure and stop the timer?
View 9 Replies
View Related
May 25, 2007
I'm using Application OnTime to fire a procedure every 30 mins. It works great, but the workbook tries to reopen itself when i close it (but not if i close excel entirely). I assume this is because I haven't stopped it anywhere. So I put a call to a procedure that has: Application.OnTime RunWhen, cRunWhat, , False
In the "Workbook_BeforeClose" event. This doesn't solve the problem. What am I missing?
Private Sub Workbook_BeforeClose(Cancel As Boolean)
StopTimer
End Sub
Private Sub Workbook_Open()
StartTimer
End Sub
(module1)
Public RunWhen As Double
Public Const cRunIntervalSeconds = 1800 ' thirty mins
Public Const cRunWhat = "dothis"...............................
View 8 Replies
View Related
Dec 10, 2013
Why I get a debug message on the following piece of code
[URL]
VB:
Sub Macro2() '
' Macro2 Macro
' Macrorecorded 10/12/2013 by nathajos
'
[Code].....
View 5 Replies
View Related
Jun 2, 2009
I am getting frustrated with the Text to Columns Wizard. After using it once on a spreadsheet, it continues to opperate whenever I paste.
Is there a way to stop it from automatically converting text to columns when I paste?
View 5 Replies
View Related
Mar 6, 2008
I am looking to stop the user saving the sheet if certain fields are not complete.
The sheet has headers on line 4 and runs from A4 to M500
In the M cells there is a counta function to check the records are complete.
M4:M500 shows either
Complete - All records comlpete
Incomplete - something missing
Blank - nothing entered yet.
What i want to do is, if one of the cells in M shows incomplete not allow them to save the sheet until its complete.
I tried the folowing (was my attempt to modify another post)
View 10 Replies
View Related
Jan 20, 2009
I am trying to stop this code from re-occurring at the end of the spreadsheet. There are two constants that will always appear as text, one is "blank" and the other is "Grand Total". I would prefer to use "Blank" if possible. The spread sheet varies in size from day to day. I have a range right now in use up to A700. I did this because when I originally put in a column formula, it ran until 20000 + rows down. Can someone please provide me with a formula that stops this code once it reaches the bottom of my spread sheet?
View 2 Replies
View Related
Jul 4, 2009
I have a textbox in a user form that I'm using as a way for someone to view what I've written but not for them to write in. Is there a way to easily disable them from writing in the text box?
View 2 Replies
View Related
Jan 12, 2010
I'm having a problem with the screen flickering whenever a different cell is selected due to a ComboBox. I searched the forums and wasn't able to find any code that helped my problem. The fact that I wouldn't know where to insert the proper code to fix it even if I could find it doesn't help. That's why I assume the "optional code" listed at the end that I found online does not work properly because it probably isn't in the right spot. Here's the
View 12 Replies
View Related
Feb 20, 2009
Is there a way in which I can get excel not to run any formulas until I run some sort of command or click a button in order to tell it to?
For example, I have two sheets, one sheet has raw data entered manually into each cell, the other sheet has a large amount of formulas to calculate totals from this raw data. But every time a number is entered into a cell in the raw data sheet Excel says 'Calculating Cells', I want to be able to enter all my raw data, then go to my totals sheet and execute all my formulas.
View 5 Replies
View Related
Jul 17, 2008
I have a very simple userform that i'm using to allow users to name their 'location'
Private Sub CommandButton1_Click()
ActiveWorkbook.Unprotect
If Me.TextBox1.Value = "" Then
Beep
MsgBox "Please give your location a name"
TextBox1.SetFocus
Else
Sheets("Template").Visible = True
Sheets("Template").Copy Before:=Sheets(1)
ActiveSheet.Name = TextBox1.Value
Sheets("Template").Visible = False
ActiveWorkbook.Protect
Unload Location
End If
End Sub
As i'm sure you've already guessed, there is nothing stopping a user from trying to rename the new sheet with an existing name. Is there anyway of checking the entry and workbook for duplicated enteries?
View 9 Replies
View Related
Jul 6, 2006
I have a cell which references another cell (i.e. =A2). When I insert a cell above A2 the new formula becomes =A3. How do I stop it from changing?
I want to insert as many cells as I want above A2 and the cell reference will always be =A2. I played around with $'s but to no avail.
View 5 Replies
View Related
Sep 20, 2006
Everytime that I insert a row into a worksheet which a number of formulae refer to, those formulae get updated automatically in such a way that it is not in my favour.
The formulae refer to rows 2:2000 on a number of different columns. Adding a new row shifts the references to 3:2001. I presume that I can stop this from happening
Example:
= SUMPRODUCT(('List of DD Donors'!E2:E2000)*('List of DD Donors'!F2:F2000='DD Tally'!E6)*IF(DATEDIF(('List of DD Donors'!G2:G2000)-1,DATE(2006,3,31),"m")>12,12,DATEDIF(('List of DD Donors'!G2:G2000)-1,DATE(2006,3,31),"m")))
changes to...
=SUMPRODUCT(('List of DD Donors'!E3:E2001)*('List of DD Donors'!F3:F2001='DD Tally'!E6)*IF(DATEDIF(('List of DD Donors'!G3:G2001)-1,DATE(2006,3,31),"m")>12,12,DATEDIF(('List of DD Donors'!G3:G2001)-1,DATE(2006,3,31),"m")))
View 4 Replies
View Related