Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have the below code in a macro that by itself runs great. I want to stop it
at row 8. The data starts in row 9 and ends when it ends - the amount of rows always varies. I have tried using different "Do", "Do Until" but have not been successful. Any help would be greatly appreciated. Darryl Range("a8").Select Dim lastrow As Long, formRow As Long Dim i As Long lastrow = Cells(Rows.Count, 1).End(xlUp).Row formRow = lastrow + 1 For i = lastrow To 2 Step -1 If Cells(i, 31) < Cells(i - 1, 31) Then Cells(formRow, "K").Formula = "=SubTotal(9," & _ "K" & i & ":K" & formRow - 1 & ")" Rows(i).insert shift:=xlShiftDown formRow = i End If Next |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Range("a8").Select
Dim lastrow As Long, formRow As Long Dim i As Long lastrow = Cells(Rows.Count, 1).End(xlUp).Row formRow = lastrow + 1 For i = lastrow To 10 Step -1 If Cells(i, 31) < Cells(i - 1, 31) Then Cells(formRow, "K").Formula = "=SubTotal(9," & _ "K" & i & ":K" & formRow - 1 & ")" Rows(i).insert shift:=xlShiftDown formRow = i End If Next -- Regards, Tom Ogilvy "Darryl" wrote: I have the below code in a macro that by itself runs great. I want to stop it at row 8. The data starts in row 9 and ends when it ends - the amount of rows always varies. I have tried using different "Do", "Do Until" but have not been successful. Any help would be greatly appreciated. Darryl Range("a8").Select Dim lastrow As Long, formRow As Long Dim i As Long lastrow = Cells(Rows.Count, 1).End(xlUp).Row formRow = lastrow + 1 For i = lastrow To 2 Step -1 If Cells(i, 31) < Cells(i - 1, 31) Then Cells(formRow, "K").Formula = "=SubTotal(9," & _ "K" & i & ":K" & formRow - 1 & ")" Rows(i).insert shift:=xlShiftDown formRow = i End If Next |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks Tom - worked great. I discovered 2 more things not previously noticed...
If there is only line of text to a condition then it does not insert a total. Example - it starts at the bottom and goes up until 2 consecutive rows are different and inserts a blank row between them and if the next row above is different then it inserts it there (this is correct) however, it does not total that line it just keeps going up until it's finished. 2. How can I get the formulas to copy over to columns "AA, "AC", "AD" and "AJ"? Thanks again and I understand if I'm "pushing it" but I am a bit frazzled. This macro has become quite large. "Tom Ogilvy" wrote: Range("a8").Select Dim lastrow As Long, formRow As Long Dim i As Long lastrow = Cells(Rows.Count, 1).End(xlUp).Row formRow = lastrow + 1 For i = lastrow To 10 Step -1 If Cells(i, 31) < Cells(i - 1, 31) Then Cells(formRow, "K").Formula = "=SubTotal(9," & _ "K" & i & ":K" & formRow - 1 & ")" Rows(i).insert shift:=xlShiftDown formRow = i End If Next -- Regards, Tom Ogilvy "Darryl" wrote: I have the below code in a macro that by itself runs great. I want to stop it at row 8. The data starts in row 9 and ends when it ends - the amount of rows always varies. I have tried using different "Do", "Do Until" but have not been successful. Any help would be greatly appreciated. Darryl Range("a8").Select Dim lastrow As Long, formRow As Long Dim i As Long lastrow = Cells(Rows.Count, 1).End(xlUp).Row formRow = lastrow + 1 For i = lastrow To 2 Step -1 If Cells(i, 31) < Cells(i - 1, 31) Then Cells(formRow, "K").Formula = "=SubTotal(9," & _ "K" & i & ":K" & formRow - 1 & ")" Rows(i).insert shift:=xlShiftDown formRow = i End If Next |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
inserting rows inbetween rows of data ? | Excel Discussion (Misc queries) | |||
Copying & Inserting Rows w/o Affecting other Rows Etc. | Excel Worksheet Functions | |||
Inserting Blank rows after every row upto 2500 rows | Excel Worksheet Functions | |||
Why is inserting rows throwing off my hidden rows | Excel Programming | |||
Inserting multiple rows in excel with data in consecutive rows | Excel Programming |