G
Guest
Good morning or evening! I want to change the iLastRow when the rows are inserted. However, the loop ends when i = 22, even though the iLastRow is actually changed to 29 for example. Please advise me what is wrong here. Thanks
iLastRow = 2
For i = iRow To iLastRo
Set oCell = ws.Cells(i, iCol
Set nextCell = oCell.Offset(1, 0
If nextCell.Value <> "" The
iDiff = DateDiff("m", oCell.Value, nextCell.Value
If iDiff > 1 The
Set rngInsert = ws.Range(Cells(i + 1, iCol), Cells(i + iDiff - 1, iLastCol)
rngInsert.Selec
Selection.Insert Shift:=xlDow
'i + iDiff -
ws.Cells(i + 1, iCol).Value = DateAdd("m", 1, oCell
'Fill dow
ws.Range(Cells(i, iCol), Cells(i + 1, iCol)).Selec
Selection.AutoFill Destination:=ws.Range(Cells(i, iCol), Cells(i + iDiff - 1, iCol)), Type:=xlFillDefaul
ws.Range(Cells(i + 1, iLastCol), Cells(i + iDiff - 1, iLastCol)).Value =
'Increase
i = i + iDif
iLastRow = WorksheetFunction.CountA(ws.Columns(iCol)
End I
End I
Next i
iLastRow = 2
For i = iRow To iLastRo
Set oCell = ws.Cells(i, iCol
Set nextCell = oCell.Offset(1, 0
If nextCell.Value <> "" The
iDiff = DateDiff("m", oCell.Value, nextCell.Value
If iDiff > 1 The
Set rngInsert = ws.Range(Cells(i + 1, iCol), Cells(i + iDiff - 1, iLastCol)
rngInsert.Selec
Selection.Insert Shift:=xlDow
'i + iDiff -
ws.Cells(i + 1, iCol).Value = DateAdd("m", 1, oCell
'Fill dow
ws.Range(Cells(i, iCol), Cells(i + 1, iCol)).Selec
Selection.AutoFill Destination:=ws.Range(Cells(i, iCol), Cells(i + iDiff - 1, iCol)), Type:=xlFillDefaul
ws.Range(Cells(i + 1, iLastCol), Cells(i + iDiff - 1, iLastCol)).Value =
'Increase
i = i + iDif
iLastRow = WorksheetFunction.CountA(ws.Columns(iCol)
End I
End I
Next i