Pulling report from SQL

Godders199

Active Member
Joined
Mar 2, 2017
Messages
288
Hello, i have the following code which runs ( slowly) to pull two reports from an SQL internet database, just seems to run slowly, have had timer on the last few days and it takes between 294 seconds and 684 seconds to complete. my problem is that when i use debug step through it only takes 148 seconds.

Is there a reason why it takes so much longer when left to run from start to finish.

Dim t
t = Timer
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.Calculation = xlCalculationManual

Sheets("checksmart").Visible = xlSheetVisible
Sheets("checks").Visible = xlSheetVisible
Sheets("Info").Select
Calculate

Qlink = Sheets("Info").Range("A56").Value

Sheets("checkSmart").Select

Range("A1:AZ50000").Select
Selection.ClearContents
Range("L:L").NumberFormat = "dd/mm/yyyy mm.hh"
Range("u:u").NumberFormat = "dd/mm/yyyy mm.hh"
ActiveWorkbook.XmlImport URL:=Qlink, ImportMap:=Nothing, Overwrite:=True, Destination:=Range("$A$1")

Sheets("Info").Select


Qlink = Sheets("Info").Range("A69").Value

Sheets("checks").Select

Range("A1:AZ50000").Select
Selection.ClearContents

ActiveWorkbook.XmlImport URL:=Qlink, ImportMap:=Nothing, Overwrite:=True, Destination:=Range("$A$1")

Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.Calculation = xlCalculationAutomatic
Sheets("checksmart").Visible = xlSheetHidden
Sheets("checks").Visible = xlSheethiddden

Sheets("instructions").Select
MsgBox Round(Timer - t, 2) & "sec."
End Sub
 

jimrward

Well-known Member
Joined
Feb 24, 2003
Messages
1,706
Are you clearing all existing data before loading up new data, personally I would delete the current sheet and create a new one with same name rather than selecting a huge range unless of course you have formulas on the worksheet
 

Godders199

Active Member
Joined
Mar 2, 2017
Messages
288
Thanks, apart from formatting no formulas, will google to find out how to code in new sheet
 

Forum statistics

Threads
1,081,615
Messages
5,360,037
Members
400,565
Latest member
Tommy O

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top