0

This code is not happening in the correct order.

I want to use the RefreshAll function to pull the data, then calculate the worksheet and then apply the IF statement. Currently the calculation seems to happen lastly, so I have to run the code twice to get the desired result.

What do I need to do to force the correct order?

Public Sub version_control()
    ThisWorkbook.RefreshAll
    Worksheets("VC").Calculate
    If Sheets("VC").Range("A1").Value <> Sheets("VC").Range("A2").Value Then 
        MsgBox "Please download the latest version from the Sharepoint"
        Application.Quit
    End If
End Sub
Asger
  • 3,822
  • 3
  • 12
  • 37
  • 1
    The `.RefreshAll` is probably running in the background. – CLR Feb 07 '19 at 16:29
  • 3
    On each connection ,check if *Enable Background Refresh* is ticked in Connection Properties. If so, un-tick it so that processing stops until the refresh is complete. – CLR Feb 07 '19 at 16:31
  • See this: https://stackoverflow.com/q/22083668/10908769 and try a `DoEvents` after `RefreshAll` ... or some of those other suggestions. – Asger Feb 07 '19 at 16:36

0 Answers0