Help to use an array for this little section of code

bensdb

New Member
Joined
Jan 24, 2014
Messages
18
Hi.
I have a large GUI with loads of macro's. This small section of code is running very slow (about 2 seconds sometimes- which is quite considerable for such a small bit of code), and i would like to be able to make it go faster.
I think it is because it is deleting rows of data in a sheet, in a loop.

I was thinking that if I passed the data to an array to start, and then did the same processes to it that it would probably be faster. Obviousley I would have to redim the array in the loop. What do you think...would it be faster or am I wasting my time?

What I really want is help making this work as an array. I wrote this chunk of code at 2am one night after hours on it, and cannot get my head round the logic
Code:
x = 0
For i = 0 To sdlr
        poo = 0
        z = 5
        
        Do While ws2.Cells(i + 2 + x, z) = "" And z <= weeks + 4
        poo = poo + 1
        z = z + 1
        Loop
       
        If poo = weeks Then
        ws2.Rows(i + 2 + x).Delete
        x = x - 1
        End If
Next
It basically loops through my range, and where all data in a row is blank apart from the first 3 columns, it deletes that row. The variable 'weeks' just corresponds to the number of columns of data there are in the range, that need to be looped through looking for blanks.

Please help a novice, vba guru's, or advise if you think the redim array method might be just as slow!!!</pre>
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Instead of the Do Loop and the If statement, couldn't you just use:
Code:
If Application.CountA(ws2.Rows(i + 2 + x)) = 0 then
ws2.Rows(i + 2 + x).Delete
x = x - 1 'Are you sure this minus 1 is correct?
End If
 
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,970
Members
449,095
Latest member
Mr Hughes

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