PC Review


Reply
Thread Tools Rate Thread

Can you speed up this code?

 
 
CLR
Guest
Posts: n/a
 
      29th Apr 2010
Hi All......
I have a user who complains that his following code runs too slow and is
wondering how it might be made faster........can anyone help please?

Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Sheets("Data Entry").Select
Range("J1").Select
x = 3
Dim y As Integer
Do While Selection.Offset(x, 0) <> ""
y = Selection.Offset(x, 0).Value
For Z = 4 To 15
Selection.Offset(x, Z).Value = Worksheets("Shop
Input").Cells(y, Z).Value
Next Z
x = x + 1
Loop

Range("A1").Select
Application.ScreenUpdating = True
End Sub

TIA
Vaya con Dios,
Chuck, CABGx3

 
Reply With Quote
 
 
 
 
RB Smissaert
Guest
Posts: n/a
 
      29th Apr 2010
Assign the relevant ranges to array like this:

Dim arr() 'this can be a lot faster than doing Dim arr

arr = Range(Cells(1), Cells(100, 5))

Then do your alterations in the array(s)

Then write the array back to a sheet range like this:

Range(Cells(1), Cells(100, 5)) = arr

Will be a lot faster.


RBS




"CLR" <(E-Mail Removed)> wrote in message
news:7895F45B-F8FD-4F28-959B-(E-Mail Removed)...
> Hi All......
> I have a user who complains that his following code runs too slow and is
> wondering how it might be made faster........can anyone help please?
>
> Private Sub CommandButton1_Click()
> Application.ScreenUpdating = False
> Sheets("Data Entry").Select
> Range("J1").Select
> x = 3
> Dim y As Integer
> Do While Selection.Offset(x, 0) <> ""
> y = Selection.Offset(x, 0).Value
> For Z = 4 To 15
> Selection.Offset(x, Z).Value = Worksheets("Shop
> Input").Cells(y, Z).Value
> Next Z
> x = x + 1
> Loop
>
> Range("A1").Select
> Application.ScreenUpdating = True
> End Sub
>
> TIA
> Vaya con Dios,
> Chuck, CABGx3
>


 
Reply With Quote
 
CLR
Guest
Posts: n/a
 
      29th Apr 2010
Many thanks RB, will give it a try.......

Vaya con Dios,
Chuck, CABGx3


"RB Smissaert" wrote:

> Assign the relevant ranges to array like this:
>
> Dim arr() 'this can be a lot faster than doing Dim arr
>
> arr = Range(Cells(1), Cells(100, 5))
>
> Then do your alterations in the array(s)
>
> Then write the array back to a sheet range like this:
>
> Range(Cells(1), Cells(100, 5)) = arr
>
> Will be a lot faster.
>
>
> RBS
>
>
>
>
> "CLR" <(E-Mail Removed)> wrote in message
> news:7895F45B-F8FD-4F28-959B-(E-Mail Removed)...
> > Hi All......
> > I have a user who complains that his following code runs too slow and is
> > wondering how it might be made faster........can anyone help please?
> >
> > Private Sub CommandButton1_Click()
> > Application.ScreenUpdating = False
> > Sheets("Data Entry").Select
> > Range("J1").Select
> > x = 3
> > Dim y As Integer
> > Do While Selection.Offset(x, 0) <> ""
> > y = Selection.Offset(x, 0).Value
> > For Z = 4 To 15
> > Selection.Offset(x, Z).Value = Worksheets("Shop
> > Input").Cells(y, Z).Value
> > Next Z
> > x = x + 1
> > Loop
> >
> > Range("A1").Select
> > Application.ScreenUpdating = True
> > End Sub
> >
> > TIA
> > Vaya con Dios,
> > Chuck, CABGx3
> >

>
> .
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to Speed Up A Code LostInNY Microsoft Excel Worksheet Functions 2 20th Jul 2009 06:18 PM
How to speed up code Dan Microsoft Excel Programming 4 31st Oct 2008 06:10 PM
speed of c# code in general compared to compiled native code Peted Microsoft C# .NET 3 17th Jun 2008 04:26 PM
Speed up Code? Sige Microsoft Excel Programming 4 27th Jul 2005 06:21 PM
Speed up code Derick Hughes Microsoft Excel Programming 0 8th Feb 2005 04:18 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:32 AM.