Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 41
Default VBA tweak to run faster? <--Rookie here

Hello -

I have the following code which is processing very slowly. Ever since
I added in the TRIM section, it has slowed way down.

FYI...the amount of active cells in column C change, so I just used a
default number of 1000, but this can be changed if needed.

Thanks for any ideas! Dan

Sub ODBC_Refresh()

' Refresh the hidden "ODBC Updates" worksheet with current data
Sheets("ODBC Updates").QueryTables(1).Refresh _
BackgroundQuery:=False

' Format UPC column into Text
Columns("C:C").NumberFormat = "@"

' Trim UPC's on ODBC Updates
Dim rng As Excel.Range
Dim cell As Excel.Range
Set rng = Sheets("ODBC Updates").Range("C2:C1000")
For Each cell In rng
cell = Trim(cell)
Next cell

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default VBA tweak to run faster? <--Rookie here

Turn off calculations, screen updating and if there is change event code then
turn off events... Something like this...

Sub ODBC_Refresh()

' Refresh the hidden "ODBC Updates" worksheet with current data
Sheets("ODBC Updates").QueryTables(1).Refresh _
BackgroundQuery:=False

' Format UPC column into Text
Columns("C:C").NumberFormat = "@"

' Trim UPC's on ODBC Updates
Dim rng As Excel.Range
Dim cell As Excel.Range
Set rng = Sheets("ODBC Updates").Range("C2:C1000")
With Application
.EnableEvents = False
.ScreenUpdating = False
.Calculation = xlCalculationManual
For Each cell In rng
cell = Trim(cell)
Next cell
.EnableEvents = True
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
End Sub

--
HTH...

Jim Thomlinson


"Dan" wrote:

Hello -

I have the following code which is processing very slowly. Ever since
I added in the TRIM section, it has slowed way down.

FYI...the amount of active cells in column C change, so I just used a
default number of 1000, but this can be changed if needed.

Thanks for any ideas! Dan

Sub ODBC_Refresh()

' Refresh the hidden "ODBC Updates" worksheet with current data
Sheets("ODBC Updates").QueryTables(1).Refresh _
BackgroundQuery:=False

' Format UPC column into Text
Columns("C:C").NumberFormat = "@"

' Trim UPC's on ODBC Updates
Dim rng As Excel.Range
Dim cell As Excel.Range
Set rng = Sheets("ODBC Updates").Range("C2:C1000")
For Each cell In rng
cell = Trim(cell)
Next cell

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 41
Default VBA tweak to run faster? <--Rookie here

On Jan 10, 8:52*pm, Jim Thomlinson <James_Thomlin...@owfg-Re-Move-
This-.com wrote:
Turn off calculations, screen updating and if there is change event code then
turn off events... Something like this...

Sub ODBC_Refresh()

' Refresh the hidden "ODBC Updates" worksheet with current data
* * Sheets("ODBC Updates").QueryTables(1).Refresh _
* * BackgroundQuery:=False

' Format UPC column into Text
* * Columns("C:C").NumberFormat = "@"

' Trim UPC's on ODBC Updates
* * Dim rng As Excel.Range
* * Dim cell As Excel.Range
* * Set rng = Sheets("ODBC Updates").Range("C2:C1000")
* * With Application
* * .EnableEvents = False
* * .ScreenUpdating = False
* * .Calculation = xlCalculationManual
* * For Each cell In rng
* * cell = Trim(cell)
* * Next cell
* * .EnableEvents = True
* * .ScreenUpdating = True
* * .Calculation = xlCalculationAutomatic
* * End With
End Sub

--
HTH...

Jim Thomlinson



"Dan" wrote:
Hello -


I have the following code which is processing very slowly. *Ever since
I added in the TRIM section, it has slowed way down.


FYI...the amount of active cells in column C change, so I just used a
default number of 1000, but this can be changed if needed.


Thanks for any ideas! *Dan


Sub ODBC_Refresh()


' Refresh the hidden "ODBC Updates" worksheet with current data
* * Sheets("ODBC Updates").QueryTables(1).Refresh _
* * BackgroundQuery:=False


' Format UPC column into Text
* * Columns("C:C").NumberFormat = "@"


' Trim UPC's on ODBC Updates
* * Dim rng As Excel.Range
* * Dim cell As Excel.Range
* * Set rng = Sheets("ODBC Updates").Range("C2:C1000")
* * For Each cell In rng
* * cell = Trim(cell)
* * Next cell


End Sub- Hide quoted text -


- Show quoted text -


Thanks so much Jim, that totally rocked!

Dan
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need someone to help tweak a code JB Excel Discussion (Misc queries) 13 January 17th 08 03:04 PM
Array Help Tweak Luke Excel Worksheet Functions 13 November 22nd 06 10:29 AM
Code Tweak bodhisatvaofboogie Excel Programming 1 July 21st 06 04:37 PM
Can someone please tweak my Macro? Wibs Excel Discussion (Misc queries) 3 December 15th 05 05:10 PM
Can faster CPU+larger/faster RAM significantly speed up recalulati jmk_li Excel Discussion (Misc queries) 2 September 28th 05 10:24 AM


All times are GMT +1. The time now is 05:25 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"