HI all,
Is it possible to change the โendโ value of a for loop whilst in the actual loop?
The reason Iโm asking is that Iโm looping through some cells in a spreadsheet and inserting rows depending on certain conditions. Iโm calculating the โlast rowโ of the spreadsheet using this piece of script:
finalrow = xlSht3.Cells(xlApp.Rows.Count, 6).End(xlUp).Row
Iโm then using this value in a for loop as shown. Because Iโm inserting rows, I need to tell the loop to now stop at the โnewโ final row, not the original one. The problem seems to be that the loop still stops at the original value and not my updated value. Any ideas?
TotalColumnLength = 1 For RowStart = 3 To finalrow If xlSht3.Cells(RowStart + 1, 2) = “” Then TotalColumnLength = TotalColumnLength + 1 Else If TotalColumnLength 3 Then xlSht3.Cells(RowStart + 1, 2).EntireRow.Select If TotalColumnLength = 1 Then xlApp.Selection.Insert Shift:=xlDown xlApp.Selection.Insert Shift:=xlDown RowStart = RowStart + 2 finalrow = finalrow + 2 Else xlApp.Selection.Insert Shift:=xlDown RowStart = RowStart + 1 finalrow = finalrow + 1 End If TotalColumnLength = 1 Else TotalColumnLength = 1 End If End If Next RowStart