Macro was fast, now slow

AlexSlivi

New Member
Joined
Jun 17, 2011
Messages
19
I have a macro that was taking about 15 seconds to run that is now taking over half an hour (without making any changes)...it's a shared network/server but I've tried it at various times during the day.

This is one of the parts it is now taking forever in:

Code:
k = 1
Seek #1, 1
  Do While Not EOF(1)
    Line Input #1, Data
    Worksheets("Template").Cells(k, 1) = Mid(Data, 1, 155)
    Worksheets("Template").Cells(k, 2) = Mid(Data, 156, 19)
    Worksheets("Template").Cells(k, 3) = Mid(Data, 175, 61)
    k = k + 1
  Loop

(It has to read in about 20,000 lines)

Do you have any idea why this would be taking forever now when it didn't used to?

Thanks,
Alex
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Try adding these to the beginning and end of the macro:

Rich (BB code):
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

' Your code here...

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True


 
Upvote 0
Do you have an formulas referencing those cells? If so try setting Calculation to Manual. Also, do you have any event code in the workbook? If so you may need to disable events. What's the purpose of this line?

Code:
Seek #1, 1
 
Upvote 0
Most important, read in the text file in an array, and output it to the sheet in one operation. Constantly writing to a sheet takes time.

In the array, chop up the lines in 3 parts. Use Data > Text to columns to split to the other columns.
 
Upvote 0
Okay, thank you all. Desu's thing worked but I will try your ideas too to see if I can speed it up even more!
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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