Same piece of code (with 20 Modules) produces different results

VBAProIWish

Well-known Member
Joined
Jul 6, 2009
Messages
1,027
Office Version
  1. 365
Platform
  1. Windows
Hello all,

I have a large program that spans 20 modules. If I run all 20 modules using a call command without a breakpoint, the code results in providing incorrect data. but if I put in just 1 breakpoint at around module 18 and then resume the code to finish through module 20, the code produces the correct result.

Anyone have any idea how or why this happens and how I can prevent it?

I don't want to have to create a breakpoint just so the code produces the correct result.

Thanks
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Does your code refresh anything? That sounds like a timing issue to me.
 
Upvote 0
Hello Rory, yes, I have at least one refresh command and it's in Mods 13, 26, 27 and several in Modules 28 and 29 (same refresh command)

That code is....
VBA Code:
 ActiveWorkbook.RefreshAll

I guess I had more than 20 modules.
 
Upvote 0
That probably explains it then. Most likely something that you are refreshing is set to refresh in the background, so the code carries on before it has finished its refresh.
 
Upvote 0
Oh, thanks for that. So what can I do about that? Can I create a 5 second pause after each refresh? If so, do you have the code for that?
 
Upvote 0
Turning off the background refresh is simpler and more effective.
 
Upvote 0
Please forgive my ignorance but I am not sure what that means?

What is "background refresh"?

I don't think I can delete the "ActiveWorkbook.RefreshAll" code because I remember having issues not refreshing the workbook when it wasn't there. Of course, I am having different issues now. Not sure what my next step should be. Thanks
 
Upvote 0
In the queries pane, right-click each query and choose Properties, then make sure the highlighted option is not checked:
1699861980442.png


and do the same for any Connections you have.
 
Upvote 0
I feel a bit silly to even say this but I have no queries or connections?
From the Excel workbook and on several different random worksheets, I clicked on "Data" and clicked on "Queries and Connections" and while the "Queries and Connections" pane did show up, it says "0 queries" and "0 connections".
 
Upvote 0
What are you refreshing then? Pivot tables? If they are based on the data in the workbook, then the refresh is not the cause of your original problem.
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,958
Members
449,096
Latest member
Anshu121

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