Hi,
I have a macro that looks like this:
It takes about a minute to finish the macro loop.![]()
Please Login or Register to view this content.
It is going through a table of 270,725 cells.
Is there any way to speed this up?
Hi,
I have a macro that looks like this:
It takes about a minute to finish the macro loop.![]()
Please Login or Register to view this content.
It is going through a table of 270,725 cells.
Is there any way to speed this up?
In general manner to go faster avoid direct access to cells.
Copy the complete used range to an array, then treat the data inside the array, then copy back the modified array to the range.
If you could attach a short sample of your data, it will possible to prepare an update
- Battle without fear gives no glory - Just try
In general, I agree with PCI concerning using an array. However, you may get adequate performance by just restructuring your variable definitions a bit.
You are defining most of the variables a Ranges.
However all you appear to be interested in is their respective text value. These ranges all are from row 2 and are not modified by the code, hence their values remain the same during execution. To prevent repeated access to these Ranges in the "Select Case" statements, these variable can be redefined as String.![]()
Please Login or Register to view this content.
![]()
Please Login or Register to view this content.
TnTinMN,
Thanks for your help. I tried it out but the macro is now 3x slower. Original took 1.5min, yours took 4.5min.
PCI,
I tried to make it in an array, and I've done that part successfully. However, I'm having trouble looping through these array.
I've tried to run it but it ran over 10+ min when I cancelled it.![]()
Please Login or Register to view this content.
When I cancelled it, it gave me an error "Run-Time error '9': Subscript out of range" and highlighted line "Select Case arrClass(r, c)"
I added "*" comment on the highlighted line.
Also, I added "**" comment on lines ".Cells(r, c + 1) = vbNullString" lines where I don't know if that is the reason why it is taking so long.
Is there a way to make arrClass(r, c + 1) = vbNullString and when loop finishes, it updates the table to equal the array?
Thanks guys
PHP Code:
Redim Arr(1 to 1, 1 to 10) As String
Dim J%
For J = 2 To 20 Step 2
Arr(1, J/2)= Cells(2, J).Value
Next j
Sa DQ,
Sorry, I don't understand that code... How does it apply here?
I figured it out how to array and put back to sheet. And now it takes 7seconds (from 1m30sec).
![]()
Please Login or Register to view this content.
Oops. I used the Text property on the Range and that is slow as it needs to format the value.
This is probably not needed, but here is the revised code in case you want to test it against the array method. I also change the Mid function to use MID$ as that is supposedly faster.
![]()
Please Login or Register to view this content.
"I figured it out how to array and put back to sheet. And now it takes 7seconds (from 1m30sec)."
Good news
You could also see ( NOT TESTED here )
change
to![]()
Please Login or Register to view this content.
and use![]()
Please Login or Register to view this content.
and after see with![]()
Please Login or Register to view this content.
In the way to did you save memory but perhaps a bit slower![]()
Please Login or Register to view this content.
Last edited by PCI; 05-17-2015 at 04:29 AM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks