Convert this loop to array

mahmed1

Well-known Member
Joined
Mar 28, 2009
Messages
2,302
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi

Hope you are well - is there any chance someone can help me convert this code from loop to an array as its taking so long to update

I have a sheet with multiple formulas therefore when looping through and pasting into sheet its taking ages so i just need to speed this code up by putting into an array and then pasting 1 time into the sheet
Hoping someone can help me please

Thank you


VBA Code:
For i = 5 To Lrow

If Queue_Split_Sh.Cells(i, 13).Value = 1 Then

First_1 = Queue_Split_Sh.Cells(i, 11).Value + 13

Last_1 = Queue_Split_Sh.Cells(i, 12).Value + 13

A = 1

For c = First_1 To Last_1

Queue_Split_Sh.Cells(i, c).Value = A

A = A + 1

Next c

End If

Next i



Application.ScreenUpdating = True

MsgBox "Updated", vbOKOnly, "Updated"
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hey - any luck

The code works fine but too slow so was hoping someone can help me with an array solution to speed it up
 
Upvote 0
Hi apologies

i have a range of cells where in each row there could be consecutive 1s

What im trying to do is look at each row and check to see there are any consecutive 1s in there..if there is then replace those cells with sequence 1,2,3 etc

So for example

Say in the first row being 5 has all 0s then go to next Row

If the first row only has 1 once then go to next row

If it has say consecutive 1s ie 1,1,1,1 then replace with 1,2,3,4 (so replacing the 1s to numbers from 1 to the count of 1s in that sequence)

There wont be multiple sets of 1s in a row so can move to next row until last row

The loop works fine but it tries and pastes at every time it finds a consecutive 1

What i was hoping to do is store the location and values into an array and then paste into cell in 1 go at the end

Hopefully im making sense

Thats why i have a formula first_1 and Last_1 to give me position of the cells to loop through and add 1
 
Upvote 0
The row data is from column N to AF so the match formula just get the position of first 1 and last 1 and then i have a condition to check to see if there is a consecutive 1 match but dont think thats the issue - i may be wrong but its this part i think is causing the issue

Queue_Split_Sh.Cells(i, c).Value = A
A = A + 1
 
Upvote 0

Forum statistics

Threads
1,223,627
Messages
6,173,421
Members
452,514
Latest member
cjkelly15

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