Slow Code Execution

May 9, 2007

I have the following piece of

Sub Summarise_Variations()

Dim myRange As Range
Dim Write_Cell As Long

With Application

.Calculation = xlCalculationManual
.StatusBar = "Please wait - Summarising variations..."

End With

It happily goes through a list and sums multiple records. It might not be the most efficient or best way to do it but it works and when I run it on a couple of stand alone sheets it takes a couple of seconds to process if that.

Unfortunately when I run it as part of the overall application that I've developed it takes ages to run, i.e. more like ten minutes.

The spreadsheet has a few graphs and about 250 sumproduct and array formula live in it but all other formula on other sheets are created and then paste valued as part of other VBA routines. As you can see I've also turned calculation off as the procedure runs so don't understand why it is suddenly taking so long.

View 9 Replies


Slow Execution Before Interruption

Jun 21, 2006

I have a macro that opens various files (via a loop) and then goes to each worksheet (via another loop) and looks through each row of data (a third loop).

Each worksheet can have over a thousand rows of data. Once I hit the button for the macro to run, it runs without any error messages, but it seems to take forever.

When I hit escape twice to interrupt the macro and then press the 'play' button, it zips through and finished running the macro really quickly. The interruption point is generally somewhere within the third loop.

It's almost as though it falls asleep and I have to wake it up.

View 9 Replies View Related

Code Execution Has Been Interrupted (code Halts)

Sep 12, 2008

I have been trying to track down why this message keeps on popping up, doesn't matter what excel file I open it always pops up, code will halt at different times in the code.

View 9 Replies View Related

Time Limit On Code Execution

Jul 8, 2009

I have a function which will allow me to search for combination of numbers which will sum to zero. However, because the range could be as long as 300 rows or even the possibility of not finding the combination that will sum to zero, the macro will take ages to complete or even causes the whole excel to hang. So What i want is to instruct macro to stop doing the search if it cannot find the results after say 20 minutes of searching.

Is that possible?

View 14 Replies View Related

Error / Code Execution Has Been Interrupted

May 20, 2013

I have created two userforms which allows people to log-in to the worksheet.

The code works great on the first go, sometimes even twice, but after a while I get taken to the VBE and shown the message "Code execution has been interrupted". And highlights a certain part of my code (highlighted in red below).

I will copy all of the code relating to the userform below.

UserForm Code

Private Sub CancelButton_Click()
Unload Me
End Sub
Private Sub ClearButton_Click()
TextUsername.Value = ""
TextPassword.Value = ""
End Sub


View 1 Replies View Related

VB Code Execution On Worksheet Change

Sep 16, 2009

What is the key word sequence to cause VB code to execute on a worksheet change?

View 9 Replies View Related

Code Execution Has Been Interrupted At Random

Jan 5, 2004

There is definite problem, as the "Code execution has been interrupted" error message appears seemingly at random (although if the workbook doesnt change it is the same points), and for no reason.

If I click the continue button the macro runs exactly as planned, but still there seems to be no rhyme or reason as to why this happens!

It even invokes on the workboon_open function.

View 9 Replies View Related

Web Queries Don't Refresh During Code Execution

Sep 9, 2006

I am writing a routine to retrieve multiple stock quotes by looping through a bunch of sheets and refreshing a bunch of querytables that access the web. My data source (Livecharts) is often clogged up and queries will fail or get lost in space so after initiating the queries I wait for a while using a waitable and then check to see if each query has completed or is still refreshing. If they are still refreshing I cancel them and refresh again. Or at least that was the plan. What I have discovered is that as long as the vba code is running the results from the queries do not come back into excel. As soon as the code is exited or I go into break mode in the debugger the queries complete.

Is there some way to get the queries to refresh during code execution? Here is a code snippet that shows what I am trying. I have defined a Class Module defining an "EventfulQTable" and it's associated methods and properties so I can have a QueryTable with events. The sub Wait uses the windows API SetWaiTable command to pause for a specified period of time. It includes a DoEvents command which I thought would allow the returning queries back into Excel but no such luck.

Sub Refresh_Queries()
Dim SheetNum As Integer, ListSheet As Integer
Dim eqtQT As New EventfulQTable
Dim QueriesDone As Boolean

SheetNum = 1
ListSheet = 12
QueriesDone = False

On Error Goto QueryError

View 4 Replies View Related

Change Manual Execution To Automatic Execution

Jun 1, 2007

I have this codes which will only trigger if I manually execute it. What do I need to do to trigger it automatically whenever the worksheet change.

Below is the codes:

Sub Risk_Color()

Dim c As Range, myFontCol As Integer, myCol As Integer

For Each c In ActiveSheet.Range("f7:g20000")
myFontCol = xlAutomatic
myCol = xlNone
Select Case c.Value
Case Is = 1, 2, 3
myCol = 34
Case Is = 4, 5, 10, 20: myCol = 43
Case Is = 30, 40, 50: myCol = 6
Case Is = 70, 100, 140, 150
myCol = 5
myFontCol = 2

View 9 Replies View Related

Code Execution Has Been Interrupted On Running Macro

Jun 9, 2009

Now..when I run any of my macros, I get the following message.. "Code Execution has been interrupted".

I'm not sure why I'm getting this message but it happens everytime I run ANY macro. Note that if I hit "Continue" every time it gives me the option, I am able to successfully run the macro, but obviously, I shouldn't have to do this.

View 5 Replies View Related

Writing The VBA Code For The Objects Created During Execution.

Apr 27, 2006

See the attached Workbook, which explains the problem easier.

View 9 Replies View Related

Code Execution Has Been Interrupted (application Setting Change?)

Mar 11, 2009

I wrote a very simple macro in an Excel file a few months ago. Worked great. Worked on my computer, and worked on a dozen other people's computers perfectly. Now, months later, ONE person is getting the error message 'Code execution has been interrupted' every time she runs the macro. I've tested it on my computer with Excel 2007, and it worked. Tested it on another computer with Excel 2003 (offending computer has Excel 2003), and it worked again. So I tested a third computer on Excel 2003, and it worked again. I'm 100% positive the macro code isn't causing this error. This makes me think that it's related to an application setting that was changed somehow.

View 5 Replies View Related

Creating A Timer To Measure Macro Code Execution Times

Sep 7, 2006

I am looking for a way to measure how long it takes to complete a sub routine in VBA. I have code which posts data to matlab and then calls it back. What I need to know is how long does it take to complete each subroutine.

create a code which will measure this? I need to measure the time taken in 100ths of a second.

Is there any simple code to complete this? I am pasting a sample of my code which is using Matlab as a COM server.

Dim Matlab As Object
Dim MReal(10, 0) As Double
Dim i As Integer
Dim j As Integer
Dim MImag() As Double
Dim value As Double
Dim RealValue As Double

I am sure I woould need to declare the timer but I do not know where and I am not sure of the syntax.

View 9 Replies View Related

Messagebox Prompt Then Allow User To Enter Data Before Continuing Code Execution

Jun 11, 2013

Basically, in the "Thisworkbook" code , i have some code in the Workbook_BeforeClose section. Currently , it autosaves the workbook in a folder i have specified.

However, i need to add some code.I want to check that a certain cell has a value in it before the user closes the workbook, and if the cell is empty, show a messagebox asking him to enter a value.

I know how to get a messagebox to pop up, the only thing is once the user clicks the OK button,
i need the rest of the code execution to pause, allowing him to make the change then if he clicks the "X" (top right of the screen) to close the file or application, the filesave dialog appears and he can then save the document.

how to go about this because at the moment when user clicks ok, the messagebox just disappears and filesave dialog appears and he doesn't have a chance to edit the cell.

View 5 Replies View Related

Slow Running Code

Nov 6, 2008

My code runs so slow! The sheet only has 233 rows and 6 of them are not in the loop.

View 6 Replies View Related

Very Slow Small Vba Code

Mar 27, 2009

Very slow small vba code. I have the following

View 2 Replies View Related

Slow Inefficient Code

Aug 4, 2008

way the code below can be made more efficient? Basically, I drop down a combobox, and based on the value i select, it populates a lot of textboxes etc based on the listindex.....

Private Sub ComboBox3_Click()
On Error Resume Next
With Me.ComboBox3
If .ListIndex = -1 Then Exit Sub
Label23.Caption = Sheets("overview").Cells(.ListIndex + 2, "c").Value
Label24.Caption = Sheets("overview").Cells(.ListIndex + 2, "b").Value
Label38.Caption = Sheets("overview").Cells(.ListIndex + 2, "d").Value
TextBox1.Text = Sheets("overview").Cells(.ListIndex + 2, "e").Value
TextBox2.Text = Sheets("overview").Cells(.ListIndex + 2, "f").Value
TextBox3.Text = Sheets("overview").Cells(.ListIndex + 2, "g").Value

It takes about 10 seconds every time i choose another project

View 9 Replies View Related

Stepping Thru Code Very Slow

Mar 8, 2007

I do those things, I set every object = nothing... I even moved them up to right after I use the object. When I open the workbook, my process's shows excel at 38000K. my first go of running code, stepping thru is great... I watch my process and see that I get up to 78000K... I then exit my code, properly... and the process goes only down to about 50000K. If I run it a 2nd time excel process show almost a 100000k and stepping thru is slow, slow motion... a 3rd time and I am at 120000k. I am setting everything to nothing and can't figure it out... I have done bigger projects with more forms, recordsets, collections and never have had this problem.

View 2 Replies View Related

Slow Code For Hiding Rows

Sep 15, 2009

I have some code which looks for the word "Out" in column "L" and hides the row if it finds it. This is running from row 24 to 160 and takes about a minute to run. I've tried two different solutions, neither really quicker than the other.

View 3 Replies View Related

Why Is My Code So SLOW, Anyway To Make It Faster

May 3, 2009

I am only looping it through about 4 thousand records, looking for match and dups and moving it over to the other sheet, so why is my code running so slow?

I have run other programs where the records are in 40 thousand and it doesn't take as long as it is right now. Is there a way to make code run faster?

View 9 Replies View Related

Code Get Slow Down When Trying To Print The Worksheet

Aug 18, 2009

I have a some code that we use in our office that works ok on my pc. When others in the office try to use the macro the year gets changed to 19 instead of 09. The only problem I have is that the code seems to slow down when it is trying to print the worksheet out. Can the code be shortened up/cleaned up. We are looking for gridlines with inside /outside lines, landscape and left/right margins of .25

Sub IC_Delays()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Windows("Delays List.xls").Activate
Range("F15:N" & Cells(Rows.Count, "F").End(xlUp).Row).Copy
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Range("A1:I" & Cells(Rows.Count, "A").End(xlUp).Row).Select.........

View 9 Replies View Related

Finding Sets Code Slow To Run

Aug 23, 2006

If you open the file sets.xls, you will see that I have listed 5 sets of 10 numbers.

These sets are such that all 10 numbers matches with sets of 20 numbers listed vertically in the range K1:S20 atleast twice (T21:T25 -twice)

I know there are 50+ sets like these and I have listed just 5 of them.

How can I search the other sets?

I have uploaded a zip file which has an excel file. Run the module "DoIt" and you will get all 50+ sets like these.

The problem is that the module takes 42 minutes on my Celeron 800 Mhz 256 MB SDRAM. I want to reduce this time.

View 4 Replies View Related

Copy/Paste Code Running Very Slow

Apr 4, 2009

The code opens a varying workbook with the same format as the source workbook and copies specific columns into the source workbook.

It is currently taking about 20seconds to run.

The worksheets are protected and have merged cells hence the call TestMe line.

View 13 Replies View Related

Calculation Code For Calculator Runs Slow

Oct 1, 2006

I am making a small push button calculator to enter data into a textbox on a userform in an add-in file and this works fairly slowly. I am trying to concatenate a list of numbers in a textbox that simulates a calculator screen when entering numbers.

Private Sub CommandButton6_Click()
Dim Val
Val = "6"
Dim valand As Range
Set valand = ThisWorkbook.Worksheets("Stageing").Range("K65536").End(xlUp).Offset(1, 0)
valand = Val
Dim A As Range, B, C, d, E, F, G, H, I, J
Set A = ThisWorkbook.Worksheets("Stageing").Range("K2")
Set B = A.Offset(1, 0)
Set C = B.Offset(1, 0)
Set d = C.Offset(1, 0)
Set E = d.Offset(1, 0)
Set F = E.Offset(1, 0)
Set G = F.Offset(1, 0)
Set H = G.Offset(1, 0)
Set I = H.Offset(1, 0)
Set J = I.Offset(1, 0)
TextBox1.Value = A & B & C & d & E & F & G & H & I
End Sub

View 4 Replies View Related

Optimize Slow Conditional Formatting Code

Jan 23, 2008

I am having a little trouble with this code, which runs in my simple but efective ressource overview. It loops through a rather large range and assigns interior colour to the cells based on certain criteria. On my stationary machine (Excel 2003) it takes approximately 15-30 seconds to run the code which is acceptable. On my laptop (Excel 2007) it takes 5+ minutes which is unacceptable. Is there a workaround so as to optimize the speed? Further, when I run this workbook on Excel 2007, even entering an integer in the sheet takes 3-4 seconds, and no code is running! In my first version I used a Change_Event to colour cells on the fly but this was slow and prevented multible cell editing as well as pasting values into the appropriate range.

Public Sub Farvelade()
Dim icolor, Navn As Integer
Dim TargetRow, LastRow, Previous As Long
Dim Target As Range
MsgBox "Det kan tage 15-30 sekunder at opdatere ressourcekalenderen"
Range("A5"). CurrentRegion.Select
'Set range
ActiveCell.Offset(Selection.Rows.Count, 0).Activate
LastRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row.....................

View 8 Replies View Related

Optimize Slow Code And Avoid Copy To Clipboard?

Oct 7, 2013

this code to minimize it and avoid copy to clipboard.

Sub SapOutputRun()
Application.EnableEvents = False
Application.ScreenUpdating = False


View 2 Replies View Related

Opening Text File Makes The Code Slow

Feb 19, 2012

I am using the below to open a text file and copy the used range to my working workbook. The opening of the file makes the code slow and and also it may be bcoz i am trying to paste 11800 lines of data from one file to another.

Also i can see the flickering of the screen when the files are open. How to make the code faster and more efficient.

Sub readSimFile()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

[Code] ......

View 5 Replies View Related

Speed-up Slow Macro Code: Entries In Column 73 - 85 Will Be Copied From WorkbookRust To The Other Workbook If The Numer In Column 5 Is The Same

Mar 25, 2008

my existing macro, as the run takes to much time to complete. (at least 20min) I've already tried several loops, but no one worked for me. Following situation: There are two excel files, entries in column 73 - 85 will be copied from WorkbookRust to the other workbook if the numer in column 5 is the same. Not every cell within this columns contains data, so the macro should automatically jump to the last entry in each of the above mentioned columns, instead of predefine the range as you see in the code below. After the data is copied to the other workbook, it will be filtered acc. to Sub FilterMain and then copied back to WorkbookRust. As already said, the whole thing works, just to lame.

Sub Allmacros()
Dim WorkbookRust As String
WorkbookRust = ActiveWorkbook.Name
ChDir "C:Documents and Settings vogtMy DocumentsRŁstplausch"
Workbooks.Open Filename:= _
"C:Documents and Settings vogtMy DocumentsRŁstplauschCH_Revenue_2008.xls"
Windows(WorkbookRust).Activate ActiveWorkbook.Name & "!UpdateEntries" ActiveWorkbook.Name & "!FilterMain"
'not ask to overwrite existing file
Application.DisplayAlerts = False
End Sub

Sub UpdateEntries()......................

View 7 Replies View Related

Hide Message Box After Execution

Nov 14, 2012

I have an inputbox that asks a question. If the user enters an incorrect response, a messagebox appears telling them to enter the correct word and returns to the inputbox. The code works fine, however the messagebox doesn't disappear after they click OK. Is there a way hide or get rid of the messagebox once they click OK or Cancel? My code is below:

VorD = Application.InputBox("Is this for Voice or Data?", "Voice or Data", Type:=2)
Application.DisplayAlerts = False
Select Case VorD


View 2 Replies View Related

Asynchronous Execution Of Macro Row By Row

Mar 7, 2013

I am trying to fix a problem that I am having with Bloomberg add-in for Excel. Each day I populate 31 days of historical price data for 500+ stocks.

$AL$3 = "=BDH(AK3,"PX_LAST",$D$1,$C$1,"DTS=h","dir=h")"
$C$1 = "=WORKDAY(TODAY(),0)"
$D$1 = "=BAddPeriods(C1,"NumberOfPeriods=-31","Per=wd","CDR=#A")"

What is supposed to happen is that in $AL$3:$BQ$3 there will be prices for 31 days.

I leave the workbook open as the Bloomberg DDE session remains open for 3 days even if the Bloomberg executable is not running.

Sometimes there is no problem and when I come into work the following day, the data is shifted forward by one day. Other times, much of the data is missing and I am forced to select and refresh each $AL$_ field. The problem with this is that for some reason the refresh is happening synchronously and I think this is causing havoc on the DDE connection and/or Excel. Resulting in slow/no updates. Also, if I refresh the worksheet some formulas will be overwritten with static data!

What I would like to do is create a macro that will:

1) clear all data in $AL$_:$BQ_$ & $BS$_:$CX_$
2) set the value of $AL$_ = "=BDH(AK$_,"PX_LAST",$D$1,$C$1,"DTS=h","dir=h")"
3) wait until the data is populated into $AL$_:$BQ$_ before going to $AL$(+1):$BQ$(+1); if $AM$_ has a value then most likely the data has populated in that row.
4) then when $AL$_:$BQ$_ is finished, do the same for $BS$_:$CX$_

I have been waiting for Bloomberg support to fulfill this request for over one month now with no results.

I have a very minute amount of code below:

PHP Code:

Sub PopulateData() PopulateData Macro Range("AL2:BQ2").Select    
Selection.ClearContentsRange("AL2").SelectActiveCell.FormulaR1C1 = _ "=BDH(RC[-1],
""PX_LAST"",R1C4,R1C3,""DTS=h"",""dir=h"")"Range("AL2").SelectEnd Sub 

View 9 Replies View Related

Copyrights 2005-15, All rights reserved