![]() |
Macro that inserts lines reply
have this macro that inserts a line if the value in D changes and copy the
value in D to A. I want this macro to only start looking in D14 or from row 14. tx for all the help Dim row_index As Long Application.ScreenUpdating = False lastrow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).row For row_index = lastrow - 1 To 2 Step -1 If Cells(row_index, "D").Value < _ Cells(row_index + 1, "D").Value Then Cells(row_index + 1, "D").EntireRow.Insert _ (xlShiftDown) Cells(row_index + 1, 1).Value = Cells(row_index + 2, 4).Value End If Next End Sub The macro works. It inserts a entire line every time the value in D changes and then copies the new value to A in the inserted line. But with at the moment my hedding in row 13 is also moved down, so I want it to start only in row 14. I a trying to make a printable price list from a DB. Thanks. |
Try changing For row_index = lastrow - 1 To 2 Step -1 to be
For row_index = lastrow - 1 To 14 Step -1 You might need to use 13 instead of 14, based on your exact requirements. "Esrei" wrote: have this macro that inserts a line if the value in D changes and copy the value in D to A. I want this macro to only start looking in D14 or from row 14. tx for all the help Dim row_index As Long Application.ScreenUpdating = False lastrow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).row For row_index = lastrow - 1 To 2 Step -1 If Cells(row_index, "D").Value < _ Cells(row_index + 1, "D").Value Then Cells(row_index + 1, "D").EntireRow.Insert _ (xlShiftDown) Cells(row_index + 1, 1).Value = Cells(row_index + 2, 4).Value End If Next End Sub The macro works. It inserts a entire line every time the value in D changes and then copies the new value to A in the inserted line. But with at the moment my hedding in row 13 is also moved down, so I want it to start only in row 14. I a trying to make a printable price list from a DB. Thanks. |
This line tells it where to stop:
For row_index = lastrow - 1 To 2 Step -1 So maybe just: For row_index = lastrow - 1 To 14 Step -1 would be sufficient. Esrei wrote: have this macro that inserts a line if the value in D changes and copy the value in D to A. I want this macro to only start looking in D14 or from row 14. tx for all the help Dim row_index As Long Application.ScreenUpdating = False lastrow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).row For row_index = lastrow - 1 To 2 Step -1 If Cells(row_index, "D").Value < _ Cells(row_index + 1, "D").Value Then Cells(row_index + 1, "D").EntireRow.Insert _ (xlShiftDown) Cells(row_index + 1, 1).Value = Cells(row_index + 2, 4).Value End If Next End Sub The macro works. It inserts a entire line every time the value in D changes and then copies the new value to A in the inserted line. But with at the moment my hedding in row 13 is also moved down, so I want it to start only in row 14. I a trying to make a printable price list from a DB. Thanks. -- Dave Peterson |
All times are GMT +1. The time now is 07:22 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com