Adding empty lines based on value via “I” loop which crashes and lags

LostandAngryatVBA

New Member
Joined
Jul 9, 2024
Messages
6
Office Version
  1. 365
  2. Prefer Not To Say
Platform
  1. Windows
Hello all,

I have been stuck 5 hours on this topic. Please help.

I have a code as below. First part is to add one empty line. Next part is an “i” loop where It is adding empty lines based on value of certain cell. This code lags my macro so bad, like 2-3min when I run it. It even crash. The ironic thing is I have 2 subs branch out and when branch 1 run this code it works fine vs when it enters another branch, it lag/crash. Therefore I know the codes work but I’m confused why one sub works fast and one die. Regardless, I’m looking to improve my codes so it doesn’t lag/crash



Application.CutCopyMode = False
Application.ScreenUpdating = False
Sheets("worksheet1").Select



Range("F2").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove



Supply = Range("AO189")
Dim i As Integer
Dim numdx As Integer
numdx = Range("t219") + 4



Range("F1").Select
ActiveCell.Offset(Tier + 7).Select ' space in inc note
For i = 1 To numdx
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Next i
 
Excellent!
Glad that you found the reason for the issue!
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,223,888
Messages
6,175,205
Members
452,618
Latest member
Tam84

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