ODBC query and save to a worksheet but PC speed gets slow

VitaminB6

Board Regular
Joined
Oct 11, 2004
Messages
208
Hi all,

Blow is my code to pull data out from a data base and then save the data to a worksheet. However, after the query is down and then switching between worksheets, my laptop loading becomes quite heavy. As I am trying to erase the data in the worksheet using clean contens, there is a message shows up which is "The range you are deleting is related to the query from external source. Except this range, would you like to delete this query? If you press "No", next time when updating the query, new data will be retrived to the worksheet". My data range is about 50 row x 78 columns.


Sheets("Raw Data").Select
Sheets("Raw Data").Range("A2:G50").Select
Selection.Clear
myCmd = "SELECT * FROM IWMES.DIMES_PPTU_PT_LTDFT Where (LOT_ID='" & LotArray(LotName - 1) & "') ORDER BY LOT_ID"
With ActiveSheet.QueryTables.Add(Connection:=myCnc1 & myCnc2 & myCnc3, Destination:=Range("A2"))
.CommandText = myCmd
.FieldNames = False
'.PreserveFormatting = True
.AdjustColumnWidth = False
.BackgroundQuery = False
.RefreshStyle = xlOverwriteCells
.Refresh
End With
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
What's the actual question?:)

The only thing I can see 'wrong' with the code is this.
Code:
Sheets("Raw Data").Select
Sheets("Raw Data").Range("A2:G50").Select
Selection.Clear
Which can be replaced with this.
Code:
Sheets("Raw Data").Range("A2:G50").Clear
If you want to suppress an alert try this.
Code:
Application.DisplayAlerts = False
And to turn them back on.
Code:
Application.DisplayAlerts = True
 
Upvote 0
Thank you for your reply.
After pulling the data in and save to a worksheet, my Excel becomes very slow especially when I change to the worksheet. Once I delete all the data in that worksheet, everything becomes ok. After save those data in a worksheet, why does my Excel becomes quite slow?
 
Upvote 0

Forum statistics

Threads
1,215,842
Messages
6,127,231
Members
449,371
Latest member
strawberrish

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