Wait for Source Document to Load before VBA runs

Glasgowsmile

Active Member
Joined
Apr 14, 2018
Messages
280
Office Version
  1. 365
Platform
  1. Windows
Good morning,

I'm running into an issue with the following code. I am attempting to open a source document, add these formulas to that document and then extract the results of those formulas. The problem (I think) is that the source document is horrible optimized and runs really slowly so this VBA works before the cells have populated correctly in the source document which often leads to the retrieved data being 0. Is there a way I can prevent this code from loading until that document has finished loading in the background?

VBA Code:
         Sheets("Cover").Range("D36").Formula = "=(AL5/Q36)*1"

         Sheets("Cover").Range("D38").Formula = "=SUM(AL5:AS5)"
         Sheets("Cover").Range("D39").Formula = "=(D38/Q36)*1"

         With Sheet8
            nextRow = .Range("B" & .Rows.Count).End(xlUp).Row + 1
            .Cells(nextRow, "B").Value = Sheets("Cover").Range("Q36").Value
            .Cells(nextRow, "C").Value = Sheets("Cover").Range("C38").Value
            .Cells(nextRow, "D").Value = Sheets("Cover").Range("C39").Value
            .Cells(nextRow, "E").Value = Sheets("Cover").Range("D36").Value
            .Cells(nextRow, "F").Value = Sheets("Cover").Range("D39").Value
            .Cells(nextRow, "H").Value = Sheets("Cover").Range("S4").Value
            .Cells(nextRow, "I").Value = Sheets("Cover").Range("S5").Value
         End With
 

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.

Forum statistics

Threads
1,215,216
Messages
6,123,669
Members
449,114
Latest member
aides

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