Forum Discussion
blank row in dates
i want blank row between different dates, and dates are adjusted in column. example if first date is 20-4-2024 second date is again 20-4-2024 but third date is 25-4-2024, third date is different then last two dates so i want a gap/blank row after 20-4-2024 which is two times. so how can i do this in my excel.
5 Replies
- OliverScheurichGold Contributor
=VSTACK(C2,REDUCE("",SEQUENCE(ROWS(C2:C15)-1,,ROWS(C2:C15)-1,-1),LAMBDA(u,v,VSTACK(IF(INDEX(C2:C15,v)<>INDEX(C2:C15,v+1),VSTACK("",INDEX(C2:C15,v+1)),INDEX(C2:C15,v)),u))))
With Office 365 or Excel for the web you can use this formula.
- NikolinoDEPlatinum Contributor
Maybe try using VBA, here is an approach.
Sub InsertBlankRowsBetweenDates() Dim ws As Worksheet Dim lastRow As Long Dim i As Long ' Set the worksheet Set ws = ThisWorkbook.Sheets("Sheet1") ' Change "Sheet1" to your sheet name ' Find the last row in Column A lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row ' Loop from bottom to top For i = lastRow To 2 Step -1 If ws.Cells(i, 1).Value <> ws.Cells(i - 1, 1).Value Then ws.Rows(i).Insert Shift:=xlDown End If Next i End SubMy answers are voluntary and without guarantee!
Hope this will help you.
- SelahMartinezCopper Contributor
Thank you, you saved my day.
- OliverScheurichGold Contributor
An alternative could be Power Query. In the attached file you can add data to the blue dynamic table. Then you can click in any cell of the green table and right-click with the mouse and select refresh to update the green result table.
That requires a VBA macro, which will work in the desktop version of Excel for Windows and Mac.
Let's say the dates are in column D, starting in D2.
Sub InsertRows() Dim r As Long Dim m As Long Application.ScreenUpdating = False m = Range("D" & Rows.Count).End(xlUp).Row For r = m To 3 Step -1 If Range("D" & r - 1).Value <> "" And Range("D" & r).Value <> "" And _ Range("D" & r).Value <> Range("D" & r - 1).Value Then Range("D" & r).EntireRow.Insert End If Next r Application.ScreenUpdating = True End SubSave the workbook as a macro-enabled workbook (*.xlsm) and make sure that you allow macros when you open it.