My code starts with a defined range from k = 2 to the total number of rows in the worksheet. The k is used to identify the row I'm at within the worksheet. TotNumOfUsedRows is found by Worksheets.UsedRange.Rows.Count. Within my loop I insert rows if certain criteria is met. Because I still need the program to go to the end of the used rows, I increase both my k and my total # of rows. I'm finding that it is exiting early, and it appears to do so when k = 1 more than the original TotNumOfUsedRows.
Sub InsertRows()
TotNumOfUsedRows = Worksheets("Name").UsedRange.Rows.Count
for k = 2 to TotNumOfUsedRows
logic here that sometimes adds a row(s), sometimes doesn't. Indexes with k to determine which row it's on
k = k + number of rows added
TotNumOfUsedRows = Worksheets("Name").UsedRange.Rows.Count
Next k
Can I change k and TotNumOfUsedRows within the for loop and have it be used as desired?
Thanks.
Bookmarks