Excel is not responding when executing code

Brew

Well-known Member
Joined
Sep 29, 2003
Messages
1,569
The following code works if my source records from c6:e255, but when I added more records, (c6:e365), excel locks up and is not responding:
Sub Conversion()
Dim i As Long
Application.ScreenUpdating = False
Range("g5:i" & Rows.Count).ClearContents
Range("g5").Resize(, 3).Value = Array("h1", "h2", "h3")
For i = 6 To Range("c" & Rows.Count).End(xlUp).Row
Range("g" & Rows.Count).End(xlUp).Offset(1).Resize(, 3) = Array(Cells(i, "c"), Cells(i, "d"), Cells(i, "e"))
Range("g" & Rows.Count).End(xlUp).Offset(1).Resize(, 3) = Array(Cells(i, "c"), Cells(i, "e"), Cells(i, "d"))
Range("g" & Rows.Count).End(xlUp).Offset(1).Resize(, 3) = Array(Cells(i, "d"), Cells(i, "c"), Cells(i, "e"))
Range("g" & Rows.Count).End(xlUp).Offset(1).Resize(, 3) = Array(Cells(i, "d"), Cells(i, "e"), Cells(i, "c"))
Range("g" & Rows.Count).End(xlUp).Offset(1).Resize(, 3) = Array(Cells(i, "e"), Cells(i, "c"), Cells(i, "d"))
Range("g" & Rows.Count).End(xlUp).Offset(1).Resize(, 3) = Array(Cells(i, "e"), Cells(i, "d"), Cells(i, "c"))
Next
Range("g5").Resize(, 3).ClearContents
Application.ScreenUpdating = True
End Sub
 
Try your original code, with the limit 251, as below, then increase it to, say, 261. If it works, use 271, and so on, until it locks up on you. Then, drop it down, until you get to the limit where it does't lockup. Now, try it on the other machine, with more memory. If you can increase the number there, it would then seem to be a memory problem. If not, it is not a memory problem, and we'll have to think of something else.
Code:
Sub Conversion() 
Dim i As Long 
Application.ScreenUpdating = False 
Range("g5:i" & Rows.Count).ClearContents 
Range("g5").Resize(, 3).Value = Array("h1", "h2", "h3") 
For i = 6 To 251 'CHANGE THIS LIMIT TO 251 HERE 
   Range("g" & Rows.Count).End(xlUp).Offset(1).Resize(, 3) = Array(Cells(i, "c"), Cells(i, "d"), Cells(i, "e")) 
   Range("g" & Rows.Count).End(xlUp).Offset(1).Resize(, 3) = Array(Cells(i, "c"), Cells(i, "e"), Cells(i, "d")) 
   Range("g" & Rows.Count).End(xlUp).Offset(1).Resize(, 3) = Array(Cells(i, "d"), Cells(i, "c"), Cells(i, "e")) 
   Range("g" & Rows.Count).End(xlUp).Offset(1).Resize(, 3) = Array(Cells(i, "d"), Cells(i, "e"), Cells(i, "c")) 
   Range("g" & Rows.Count).End(xlUp).Offset(1).Resize(, 3) = Array(Cells(i, "e"), Cells(i, "c"), Cells(i, "d")) 
   Range("g" & Rows.Count).End(xlUp).Offset(1).Resize(, 3) = Array(Cells(i, "e"), Cells(i, "d"), Cells(i, "c")) 
Next 
Range("g5").Resize(, 3).ClearContents 
Application.ScreenUpdating = True 
End Sub
 
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
After testing the original code further, I realize that it is working, it just take it a very long time to execute the result. It took at least 10 minutes for it to process the results for 90 records. So maybe there is another code that can be created to produce the results quicker or maybe I just have execute the command multiple times with smaller groups or records
 
Upvote 0
Brew, your code works fine for me, and I filled cols C:E down to row 455.

Although I can't work out what you are doing with this line of code:
Code:
Range("g5").Resize(, 3).Value = Array("h1", "h2", "h3")
as you do nothing with these cells, and then clear them again after the main body of the code.

10 minutes for 90 records??? When I ran with hundreds of records it took a couple of seconds.

Comment out this line of code and see how long it takes:
Code:
Range("g5:i" & Rows.Count).ClearContents
 
Upvote 0
Wow, i wish my execution would work as quickly as worksheet does, however, that the clearcontent line out, actually took a little longer. It converted only 22 records in 10 minutes before, i interrupted the progress
 
Upvote 0
Do you have a lot of calculation going on? If so you may want to switch off calculation before the processing.
 
Upvote 0
Yes, I do have a lot of calculations, how do I turn it off before processing
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,017
Members
448,936
Latest member
almerpogi

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