PC Review


Reply
 
 
leungkong
Guest
Posts: n/a
 
      23rd Jul 2009
I use the following code to write the data from a (8615 * 24) array to
worksheet
It is very fast before.
But I don't know why it is slow now.
Today, I spend 2.5 hours for this.
I want to know why and how to speed up. Many thanks.

Dim i As Long, j As Byte
For i = LBound(RMaster) To UBound(RMaster)
For j = 0 To 23
Cells(i + 2, j + 1 = RMaster(i, j)
Next
Next
 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      23rd Jul 2009
I put the code below in a new workbook and it took under 10 seconds. Try
doing hte same. I think it is the workbook and not the macro. You may have
a lot of data or fromating in the workbook which would slow down the macro.
But it also may be your PC. I would try putting the workbook on another PC
to see what happens.

Sometimes deleting rows that are not used in teh worksheet may help. If you
worksheet goes to column Z then highlight all the columns to the right of you
data and delete the columns not used. Repeat for the rows. Try for all
worksheets.


Sub test()

Dim RMaster(8615, 24)
Dim i As Long, j As Byte
For i = LBound(RMaster) To UBound(RMaster)
For j = 0 To 23
Cells(i + 2, j + 1) = RMaster(i, j)
Next
Next


End Sub


"leungkong" wrote:

> I use the following code to write the data from a (8615 * 24) array to
> worksheet
> It is very fast before.
> But I don't know why it is slow now.
> Today, I spend 2.5 hours for this.
> I want to know why and how to speed up. Many thanks.
>
> Dim i As Long, j As Byte
> For i = LBound(RMaster) To UBound(RMaster)
> For j = 0 To 23
> Cells(i + 2, j + 1 = RMaster(i, j)
> Next
> Next

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      23rd Jul 2009
> Dim RMaster(8615, 24)
> Dim i As Long, j As Byte
> For i = LBound(RMaster) To UBound(RMaster)
> For j = 0 To 23


As a side point for the OP... you didn't have to hard code the limits for the second For statement... you could use LBound and UBound for them to, just use the optional second argument to get to the second dimension's bounds.

Dim RMaster(8615, 24)
.......
For i = LBound(RMaster) To UBound(RMaster)
For j = LBound(RMaster, 2) To UBound(RMaster, 2)
......

--
Rick (MVP - Excel)


"Joel" <(E-Mail Removed)> wrote in message news:6A5A3B49-A4C5-4E8E-9BA2-(E-Mail Removed)...
>I put the code below in a new workbook and it took under 10 seconds. Try
> doing hte same. I think it is the workbook and not the macro. You may have
> a lot of data or fromating in the workbook which would slow down the macro.
> But it also may be your PC. I would try putting the workbook on another PC
> to see what happens.
>
> Sometimes deleting rows that are not used in teh worksheet may help. If you
> worksheet goes to column Z then highlight all the columns to the right of you
> data and delete the columns not used. Repeat for the rows. Try for all
> worksheets.
>
>
> Sub test()
>
> Dim RMaster(8615, 24)
> Dim i As Long, j As Byte
> For i = LBound(RMaster) To UBound(RMaster)
> For j = 0 To 23
> Cells(i + 2, j + 1) = RMaster(i, j)
> Next
> Next
>
>
> End Sub
>
>
> "leungkong" wrote:
>
>> I use the following code to write the data from a (8615 * 24) array to
>> worksheet
>> It is very fast before.
>> But I don't know why it is slow now.
>> Today, I spend 2.5 hours for this.
>> I want to know why and how to speed up. Many thanks.
>>
>> Dim i As Long, j As Byte
>> For i = LBound(RMaster) To UBound(RMaster)
>> For j = 0 To 23
>> Cells(i + 2, j + 1 = RMaster(i, j)
>> Next
>> Next

 
Reply With Quote
 
Charles Williams
Guest
Posts: n/a
 
      23rd Jul 2009
This example runs in 0.3 seconds on my system: its much faster to transfer
the data in 1 block from the array than doing it cell-by-cell.

Sub test()

Dim RMaster(8615, 24)
Dim i As Long, j As Long

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False

For i = LBound(RMaster) To UBound(RMaster)
For j = 0 To 23
RMaster(i, j) = i * j
'Cells(i + 2, j + 1) = RMaster(i, j)
Next
Next
Cells(2, 1).Resize(UBound(RMaster) + 1, UBound(RMaster, 2) + 1) =
RMaster

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True

End Sub

Charles
___________________________________
The Excel Calculation Site
http://www.decisionmodels.com

"leungkong" <(E-Mail Removed)> wrote in message
news:7F0BBEB8-BECB-44CE-B842-(E-Mail Removed)...
>I use the following code to write the data from a (8615 * 24) array to
> worksheet
> It is very fast before.
> But I don't know why it is slow now.
> Today, I spend 2.5 hours for this.
> I want to know why and how to speed up. Many thanks.
>
> Dim i As Long, j As Byte
> For i = LBound(RMaster) To UBound(RMaster)
> For j = 0 To 23
> Cells(i + 2, j + 1 = RMaster(i, j)
> Next
> Next
>



 
Reply With Quote
 
Dana DeLouis
Guest
Posts: n/a
 
      26th Jul 2009
> I want to know why and how to speed up.
> Dim i As Long, j As Byte



Hi. Just another approach...

Sub Demo()
Dim RMaster(8615, 24)
Dim d
'// Load RMaster w/ data...etc

d = Dimensions(RMaster)

[B1].Resize(d(0), d(1)) = RMaster
End Sub


Private Function Dimensions(m) As Variant
Dimensions = Array( _
UBound(m, 1) - LBound(m, 1) + 1, _
UBound(m, 2) - LBound(m, 2) + 1)
End Function


> Dim i As Long, j As Byte


I believe the consensus here in the newsgroup is that "Byte" is not
often used for a looping type. There just doesn't seem to be any speed
improvement.

Note that the number of columns is 25 (ie 0 to 24)
Perhaps you could use something like this:

Dim RMaster(1 To 8615, 1 To 24)

= = = = = = =
HTH :>)
Dana DeLouis



leungkong wrote:
> I use the following code to write the data from a (8615 * 24) array to
> worksheet
> It is very fast before.
> But I don't know why it is slow now.
> Today, I spend 2.5 hours for this.
> I want to know why and how to speed up. Many thanks.
>
> Dim i As Long, j As Byte
> For i = LBound(RMaster) To UBound(RMaster)
> For j = 0 To 23
> Cells(i + 2, j + 1 = RMaster(i, j)
> Next
> Next

 
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
is there any speed difference between a TVF CLR that returns an array vs yield as each result is ready? e.g. does returning the array all at once cause sql server to allocate more efficiently? DR Microsoft VB .NET 0 26th Nov 2007 10:59 PM
is there any speed difference between a TVF CLR that returns an array vs yield as each result is ready? e.g. does returning the array all at once cause sql server to allocate more efficiently? DR Microsoft C# .NET 0 26th Nov 2007 10:59 PM
is there any speed difference between a TVF CLR that returns an array vs yield as each result is ready? e.g. does returning the array all at once cause sql server to allocate more efficiently? DR Microsoft Dot NET 0 26th Nov 2007 10:59 PM
is there any speed difference between a TVF CLR that returns an array vs yield as each result is ready? e.g. does returning the array all at once cause sql server to allocate more efficiently? DR Microsoft ADO .NET 0 26th Nov 2007 10:59 PM
is there any speed difference between a TVF CLR that returns an array vs yield as each result is ready? e.g. does returning the array all at once cause sql server to allocate more efficiently? DR Microsoft Dot NET Framework 0 26th Nov 2007 10:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:39 PM.