How Do I Get A Loop To Resume At Break Point

Apr 24, 2008

I've got some code (at bottom) which works very well for small groups of data but when it gets large it hangs excel. Had heard that I can make code which will get it to pick up on the row after where it left off rather than having it run the entire loop again. Specifically speaking of the raw data sheet. It is sorted by date and by code so that if it works on the first code for the date it won't have to return to that row again for data. Uncertain how to implement that approach. (sample data layout below)


Option Explicit

Sub DoubleDirectionLoop()

Dim Wb As Excel.Workbook
Dim Ws1 As Excel.Worksheet, Ws2 As Excel.Worksheet
Dim iCol As Integer
Dim iRow As Integer, iRow2 As Integer
Dim Loop1 As Integer, Loop2 As Integer
Dim Loop3 As Integer, PeakSum As Long

View 9 Replies


ADVERTISEMENT

Break An Infinte Loop

Dec 30, 2006

Taking the following as an example, where you find yourself in an infinite loop. How can you interrupt the sub and keep the code. All because you where to stupid to save it before running it.

Sub TEST()

LabelA:

****MsgBox "YOU IDIOT"

****GoTo LabelA

End Sub

View 9 Replies View Related

Macro To Loop And Insert A Page-break

Feb 2, 2010

I have lurked and learned but now this is beyond me-Attached is a sample file - The tab Data is where I start the macro and it is the file( after I have cleaned it up) that I get once a week-I added Column K/L-Blank Count Sheet Format is where the macro puts the info- count sheet is what I want it to look like- Old version is how I used to present the sheets-using subtotals etc-See the print preview to see what old ver and sample look like--

This macro below starts in data and puts Column K / L on the blank and then fills them in. Field 1-5 is all one loc sequence -I have the macro going the first few steps what I have been pulling my hair out attempting to do is --If the part# stays the same keep putting the locations under each other-As I show on Count Sheet and when the part# changes put a page break in and start over again with the new part# and assorted info. The file I get each week to do this with will have from 150 to 200 part #'s. I need a page for each--Each part has from 1 to 10 location's ( The loc consists of Field1-5 alfa-numeric )

View 2 Replies View Related

Prevent Code Loop Interruption By Esc Or Ctrl+Break Keys

Nov 18, 2009

The code itself functions as desired however i am getting the vba message "code execution has been interupted". However if i comment out the line

ActiveSheet. Range("Y6:BC6").Delete Shift:=xlUp. Then all is well - so i'd say that is the culprit.

Sub Test()
If Left(ActiveSheet.Name, 5) = "query" Then
Dim intRow As Integer
intRow = ActiveSheet.Range("Y4").End(xlDown).Offset(1, 0).Row

If intRow > 25 Then
ActiveSheet.Range("Y6:BC6").Delete Shift:=xlUp
intRow = intRow - 1
Else
End If
' Runner 1
ActiveSheet.Range("Y" & intRow).Value = ActiveSheet.Range("A5").Value
ActiveSheet.Range("Z" & intRow).Value = ActiveSheet.Range("M4").Value...................

View 6 Replies View Related

Automatically Change The Point Name To Match The Point Name In Column

Dec 10, 2008

I have a pivot table as shown below which is pretty straight forward however I am trying to create a macro that will automatically change the point name to match the point name in column E then copy that resulting dispaly to another sheet then pick the next point name in line and do the same thing and repeat for 50 rows, so my end result will be 50 pivot tables ready for printing. I can do this manually but I am trying to make it automatic...BTW the point names in column E change everyday but the pivot table supports the name changes.

Option Explicit
Sub PointName()
Dim Ws As Worksheet
Dim Rng As Range, Cel As Range

Set Ws = ActiveSheet
Set Rng = Range(Cells(2, 7), Cells(Rows.Count, 7).End(xlUp))

For Each Cel In Rng
Ws.PivotTables("PivotTable1").PivotFields("Point Name").CurrentPage = Cel & " "

Ws.Columns("A:B").Copy
Sheets.Add
With ActiveSheet
.Paste
.Name = Trim(Cel)
.Range("A1").Select
End With
Next
Ws.Activate
End Sub

I turned it off for a while and when I turned it back on I am getting an error
Unable to set the _Default property of the PivotItem class

Debugger is highlighting

Ws.PivotTables("PivotTable1").PivotFields("Point Name").CurrentPage = Cel & " "

View 9 Replies View Related

On Error Resume Next ..

Jan 20, 2010

Why doesn't this code exit on the first "Cancel" selection from the first inputbox?

When I select Cancel from the first inputbox it goes to the next inputbox and I have to select Cancel again, then it exits the sub.

View 4 Replies View Related

On Error Resume Next

Apr 10, 2008

Cells.Find(What:="flags", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate
'if there is an error, ignore it and continue
On Error Resume Next
Selection.EntireColumn.SpecialCells(xlCellTypeConstants, 1).EntireRow.Delete Shift:=xlUp
'reset normal error handling
On Error GoTo 0

I am finding the cell marked "flags", then in that column look for the special cell and delete the rows where they are found. It works when it actually finds those cells, but it reports an error when no cells were found.

View 9 Replies View Related

Resume If Error

Jun 2, 2006

Is there a way to resume running a code should there be an incompatible file that causes an error? Currently I'm reading a bunch of excel sheets, but there might be some sheets that aren't formated as such and cause an error 400.

View 5 Replies View Related

On Error Resume Next Ignored

May 15, 2008

Using the code I got from the Forum Drop Down I added the subs to put a custom command button in the right menu. The first thing it does is delete any existence of the menu item so that you don't get a new one every time you right click your menu. I has just a clear as day "On Error Resume Next". But when it encounters the delete command the error dialog pops up and says "Run time error 5. Invalid procedure call or argument."

View 4 Replies View Related

If Found Rane Is Nothing Then Resume

Aug 3, 2009

I'm trying to have a macro move down one cell and resume from the start if it finds nothing.

View 14 Replies View Related

Macro Pause Then Resume By Keystroke

Nov 11, 2012

Is there a way a macro can be paused then resume running the macro by a keystroke, not a time delay.

View 3 Replies View Related

Macro To Pause Code, Another To Resume

Jul 27, 2007

I have a workbook with several hundred row the VBA code loops through. It takes about an hour to run all the calculations. Whenever I need to pause the script I hit ESC, which works well for me, but for other users it would be nice to have a command button that halts code. Even better would be another button to resume code.

View 9 Replies View Related

Resume VBA Code From Error Handler

Oct 23, 2008

Before doing some modifications in a data sheet, I first check with the below code whether a certain list is complete or not using the VLOOKUP function. If I encounter a missing value in the list, a userform appears asking to fill out 3 data fields, which are then added to the original list to complete it. All of this works fine if only one line is missing; if there are two (or more) lines missing, all goes well untill the VLOOKUP function errors out on the second line missing.
I can't find out why everythign goes welll with the first missing line, but not with the second missing line.

Sub proCheckVesselCodes()
Sheets("Sheet4").Select
Range("K1").Value = "Check"
Set varRange1 = Range("A1")
fctCountNrRows
varRow1 = varRow
varRow2 = 2

jump:
On Error Goto addvessel...............

View 3 Replies View Related

Resume Keys Normal Function After OnKey

Sep 1, 2006

I use the following code to assign a macro to right arrow key.

Application.OnKey "{RIGHT}", "myMACRO"

My questin is how to let the right arrow key resume its normal function, that is move from left to right (A2 to A1) if I do not want the macro any more and without quit and restart EXCEL? The following code disabes the right arrow key's normal function. Application.OnKey "{RIGHT}", ""

View 2 Replies View Related

Msgbox Doubleclick Resume Error Handling

Feb 1, 2007

The following code shows the bare bones which illustrate my problem. The routine runs whenever the user enters a string which begins "Frm1=" and contains exactly three commas.

My problem is with the MsgBox which appears if the ErrorHandler is reached. With the following code the MsgBox requires two clicks on OK to dismiss it. If I change Resume to GoTo it requires only one. Is this normal? Is there any way of dismising the MsgBox with one click? ...

View 9 Replies View Related

VBA Error Goto Previous Line / Statement Not Resume Next

Aug 10, 2012

I have some code below. I have error handling in place for when it tries to open a specific file. If it isn't there then user has option to continue and ignore this file, or browse and select a new one.

The problem is, when the user wants to ignore the file, the "Resume Next" continues to run the VBA assuming the file was ok i.e. the code after the line to open the file. What I would like is for it to skip the succeeding code and go to look for the next file.

Below is the VBA:

Code:
For i = 0 To 2 Step 1

'add in error handling for if the file is missing
On Error GoTo MissingFile
Workbooks.Open Filename:="\hbeu.adroot.hsbcdfsrootgb002hfcfinance01fnce" & qfolder & "Data" & qfile(i), UpdateLinks:=False, ReadOnly:=True

[Code] .........

Missing File:

qMissingPrompt = "There was an error opening data file. Click OK to browse or Cancel to ignore and move to next file"
qAns = MsgBox(qMissingPrompt, vbOKCancel)
'click cancel - ignore error and move onto the next file
If qAns = vbCancel Then

[Code] .......

So, where it says Resume Next, currently it will start running the following (after On Error Goto 0)

Code:
Set datawb = ActiveWorkbook

range("A2").Select
Do Until ActiveCell.Value = ""
etc.

What I would like it to do is go back to is to go to the next i

Code:
For i = 0 To 2 Step 1

Or even to go to the 'Next' statement at the end so that it moves onto the Next i and tries to open the next file.

View 2 Replies View Related

Page Break By Asking The Input File For Page Break To Be Done

Dec 9, 2008

The code which you provided works fine no problem for a page break. I need to run the macro for the page break by asking the input file for page break to be done.

For Example, If excel filename "A" contain the code which you have given need to ask to input the filename "B" and process need to be done in file "B".

I have added some code to your code which you provided but it gives error message "1004" "Method 'Range' of object '_Application' failed" at following line :

Set rng = oExcel.Range(Cells(2, 2), Cells(Rows.Count, 2).End(xlUp))

View 12 Replies View Related

Pause Macro And Wait For User To Click On Cell To Resume Macro?

Jan 15, 2014

I have a macro where I manually select a cell then the macro kicks in to copy and paste the contents into the Find function. From there it goes to another work sheet, clicks on a cell in column one and searches for matching cell contents. Then If false it manually goes back to the original worksheet/cell and then I input a N in the left adjacent cell. If true I enter a Y. Right now I can only run this for the specific cell the macro was recorded for. I would like to expand this.

What I would like to do create a loop in the macro that waits for my cell choice input then continues with the with the Find function. If false the macro should just loop back to the original worksheet/cell and wait for input, ie the next cell selected. However, if true a worksheet/cell is selected, a Y is input and it loops back to the original cell and waits for input.

View 9 Replies View Related

Boolean Type Mismatch Error - On Error Resume Next Doesn't Work?

Apr 1, 2013

OK, so I have a userform with some text boxes that I have specially formatted to accept only date values in the form of mm/dd/yy. By default they are blank. I have a check in one of my codes that looks like this

Code:
If DateBox vbNullString And DateValue(DateBox) > checkdate Then
M1 = "NEOPRENE" & Chr(13)
Else
M1 = "" & Chr(13)
End If

Where DateBox is this specially formatted TextBox and checkdate is a future date being checked against.So if DateBox has a value in it AND that value is greater than the date being checked against the returend string is Neoprene, otherwise it is blank.

Well the problem I have is when the first condition returns FALSE, i.e. when DateBox is empty, the DateValue half still gets evaluated and returns a type missmatch error or something like that because DateValue("") returns an error. I have line of code 8 times, one for Neoprene, squeegee, etc. So the name of the text boxes are each unique and I am using M1, M2, M3, etc.

For other reasons, use of "On Error Resume Next" doesn't work for this situation because it causes a result opposite to what I want to happen.

View 2 Replies View Related

Pause Macro, Allow Format, Resume Macro

Mar 14, 2007

how to interrupt VBA code, allow user modifications to a chart, and then continue the code where it left off with a click of a button. I currently have the code in place where a UserForm pops up at a specific point and tells the user to make adjustments and press OK when done. It works fine but the UserForm displays and the macro resumes when OK is clicked, but I can't figure out how to activate the chart or the spreadsheet to allow editing while that UserForm is on the screen. If only I can get excel to allow me to sleect the spreadsheet and make changes while the UserForm is on the screen, I would be set. Can anyone please help me with any options to allow editing while the UserForm is on the screen so I can edit and then click the OK when done?

I posted something similar to this over two years ago. The way I got around it at the time was to break the code into two separate subs. This time around, the code is making 17 graphs and I want to ask for editing for each one before continuing. That would be a lot of individual sections of code.

View 9 Replies View Related

Loop Within A Loop (repeat The Loop Values)

Mar 31, 2008

With Sheets("regrade pharm_standalone")
For Each r In .Range("standaloneTerritory")
If r.Value = "X101" Then
r.EntireRow.Copy
Sheets("X101").Range("A1").End(xlDown).Offset(1).PasteSpecial xlPasteValues
End If
Next r
End With
-------------------
I need to repeat this loop for values from X101 to X151. In all cases, the sheet name is equal to the value I'm looking up (eg: value = X102 goes to sheet X102).

I have a named range called 'territories' that contains the list of X101 -> X152.

I'm hoping to make the code perform the loop for each of the territories without my having to copy & paste and change the 'X101' 51 times as this would seem a rather silly thing to do!

View 9 Replies View Related

Loop Through Multiple Files And Call Macros (but Unable To Loop)

May 14, 2014

Macro which loops through a number of files and calls the same macro in each of them. Unfortunately when I add "Application.Run..." to the code, it no longer loops through the process and instead stops after updating the first file in the loop. If I remove the "Application.Run..." code and add any other code, the loop works fine and it continues through the process repeating all the steps for each file found.

Why it stops after one file when using "Application.Run..." to call the macros?

NB I have a list of path and file names starting in row 8 of columns A and C. Each file in the list has a macro called UpdateS1 and promoupdate1.

Sub C_Run_Loop_Macro()
Dim lastRow As Long
Dim i As Long

[Code]....

View 4 Replies View Related

Store Row Number Within Loop And Delete All Stored Rows After Loop?

Sep 11, 2013

I have working code that returns a row number within a for loop based on parameters I set.

Each time the for loop runs I would like to store this row number, then after the loop has finished, delete all stored rows.

Code:
for rowNum = 1 to x (some variable end row number which I already have worked out using End(xlUp).Row)
if x = y then
*storedRow = rowNum
end if
next rowNum
*

Lines with a * are the bits I can't work out. I've been trying to understand arrays by reading posts on what other people have done, but I can't fit (or fully understand) the reDims, or reDim preserves into my code. I've seen what appear to be quite complex ways involving uBounds and LBounds, but unfortunately I can't see how to use them.

All I want is to simply keep adding a row numbers to a variable, (i.e. row 2, 5, 20, 33, 120, etc) and then delete those specific rows.

View 4 Replies View Related

Loop Through Cells And Ranges Reverse Order With Backwards Loop

Aug 30, 2006

I am looping through each cell in a range and I would like to loop in reverse order.

Dim CELL As range
Dim TotalRows As Long
TotalRows = Cells(Rows.Count, 1).End(xlUp).Row
For Each CELL In Range("C1", "C" & TotalRows)
CELL.Select
'Code here to delete a row based on criteria
Next

I have tried:

For Each CELL In Range("C" & TotalRows, "C1")

and it does not make a difference. I need to loop in reverse order since what I am doing in the loop is deleting a row. I am looking at a cell and determining its value. If the value is so much, then the row gets deleted. The problem is that the next row "moves up" one row (taking the pervious cell's address) and therefore the For Each Next loop thinks it has already looked at that row.

View 7 Replies View Related

Copy Cells In Loop Based On Loop Increment Being Multiplied

Feb 7, 2008

I have some numbers in a column that I need to copy 12 times (each one) into another column. The problem is that I got like 200 records that will be converted in 15000 aprox. I've uploaded an example of what I need,

View 3 Replies View Related

Loop Through Index Worksheets Using For Loop And Select Clause

Nov 4, 2013

I have a workbook that contains, say, 50 worksheets: the first two worksheets summarise the data and are static in that they don't move position. However, the next four worksheets contain certain data for any given month. Each time a new month comes along, say, November, I insert four new worksheets after the two static ones as a result October's four worksheets are simply moved down the line in terms of worksheet order.

I need a macro to refer to the first six worksheets only (not the other tabs). I opted for index referencing for each worksheet, ie one - six. Now within these six worksheets in any given month, I need to sort the data by a certain column. The problem: in sheets 1,4,5 and 6 I need to rank by column E, but in sheets 2 and 3 I need to rank by column C. I have stepped through the code, which works for sheets 3-6, but doesn't seem to refer to sheets 1-2.

Sub WorksheetLoop()
'
' Loop through an indexed number of worksheets; _
' & this ensures that the worksheet range is dynamic _
' and is able to adjust when new sheets are added/removed, etc.
'
'Dim ws As Worksheet
Dim i As Long
Dim ws As Worksheet

[code]....

View 2 Replies View Related

Break The String

Dec 7, 2009

how to break the string into 3 variables.

Example: Given string is : -4.98e-005x^2+0.368x+0.0588
All the string there will be two + symbols.

I have to break the above string into 3 parts and store it into variables like
a=-4.98e-005x^2
b=0.368x
c=0.0588

View 3 Replies View Related

Break Down 1 Sheet Into Several

Jan 2, 2013

I need a macro that can take a sheet containing million rows and break it down into multiple sheets within the same workbork beginning on sheet 2 (source data on sheet 1). I would like the macro to include a input box that appears when the macro is run that asks "how many rows per sheet?"

View 2 Replies View Related

Break Up One Row Into Many Columns

Mar 15, 2009

I am herewith enclosing the sample data, which is one row, containing the branch name, branch code, itemcode, rate, qty, amount . Each branch has several items with different quantity of various rates, which has come in the horizontal line. Now I want that in one by one, for converting that data into oracle.

BR.NAME BR.CODEITEM CODEITEM RATE QTYAMOUNTITEM CODEITEM RATE QTYAMOUNTITEM CODEITEM RATE QTYAMOUNTITEM CODEITEM RATE QTYAMOUNTITEM CODEITEM RATE QTYAMOUNTxx1104.5100450153250750263.25158513.5394.5180810506.55003250result should be like thisxx1104.5100450xx2153250750xx3263.25158513.5xx4394.5180810xx5506.55003250

View 9 Replies View Related

Break All Links

Jun 26, 2009

Is there a simple code I can add to the end of my macro that will break all existing links in the active workbook?

View 9 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved