Adding Blank Row via formula/array

Labrat24

New Member
Joined
Apr 4, 2019
Messages
11
I would like to automatically add a blank row in a series of Dates so that when I graph the data there is a gap whenever there is a new month. This makes it alot easier to read when there is a bunch of data. The reason that I would like this done automatically is because I have several long lists of data that I can apply this to and it is very time consuming to manually add the blank rows. Can this be accomplished without a macro? I have an example below.

A
B
C
D
E
1
Date
Data
Date
Data
2
1/5/2019
2
1/5/2019
2
3
1/10/2019
4
1/10/2019
4
4
1/15/2019
6
1/15/2019
6
5
1/30/2019
8
1/30/2019
8
6
2/1/2019
7
7
2/8/2019
12
2/1/2019
7
8
2/17/2019
1
2/8/2019
12
9
2/25/2019
14
2/17/2019
1
10
3/1/2019
8
2/25/2019
14
11
3/15/2019
1
12
3/1/2019
8
13
3/15/2019
1

<tbody>
</tbody>
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
I think a macro is the best way to go....
Press ALT + F11 to open the VBE
In the LH window double click on "This Workbook"
In the RH window where the cursor is flashing, paste the code below

Code:
Sub MM1()
Dim r As Long, lr As Long
lr = Cells(Rows.Count, "A").End(xlUp).Row
For r = lr To 3 Step -1
        If Month(Range("A" & r).Value) <> Month(Range("A" & r - 1).Value) Then
            Rows(r).EntireRow.Insert
        End If
    Next r
End Sub

Close the VBE and then Press ALT + F8 and select the MM1 macro from the list and select run.

Job Done !!
 
Upvote 0
Michael

Entering an entire row wont work. This is just a few columns of a much larger spreadsheet. That is one of the reasons I was asking for help. The list of dates that I have is several hundred long so it takes a little bit of time to add the space, not to mention I do this for several data sets.
 
Upvote 0
So, the first comment in your question was.....
I would like to automatically add a blank row

Now you say you don't want that....can you provde more information on what is required ??
 
Upvote 0
In Post 1 you said:
I would like to automatically add a blank row

You said Row. Not a few cells.
And a formula cannot enter rows. You would need a Vba script.

More specific details are needed.
 
Upvote 0
Sorry for not being more specific. The reason that I dont think a macro will work is that my data is automatically dumped into excel using PI. I use the dates that are generated to pull additional information for that database. The way I have it set up now, I use a formula to organize the dates and remove duplicates. I have already tried "inserting" cells/rows into my dates and that ends up messing up other formulas that use the data. If there was a way to use a array/formula that would be very helpful, if not then I will continue doing it the way I have been because I dont think a macro will work. I really do appreciate the help but I understand if this is not possible.
 
Upvote 0
You simply can't insert blank rows by formula !
I can't see why a macro wouldn't work if we have the correct information.....and inserting rows shouldn't affect the formulae if done correctly.
If you would like to upload the data to DropBox and then post a link back here, we may be able to have a play with it !!
 
Upvote 0
You simply can't insert blank rows by formula !

Sure you can. That is to say, you can create an algorithm of formulas that report an array containing blanks according to conditions. The extracted data here is in ColL.

The formula in ColJ uses the new dynamic arrays from Excel365, but if you're still using old software the alternative formula in ColN will suffice (if invoked with Ctrl+Shift+Enter). I'm sure some industrious person can create a single-cell formula instead of the ones in ColF through CoL; I left the algorithm across several helper columns so it can be more easily audited.

[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
Book1
ABCDEFGHIJKLMN
5DataPointYEAR (ascending order)desired output of YEARchange?number of changes aboveimplied blank rowrow of desired outputrow of desired output, blanks excludedYEAR extractedrow of desired output (old Excel)
61200120010001120011
72200120010002220012
83200120010003320013
94200210444
105200220020105420025
116200220020106520026
127200220020107620027
138200220020108720028
1492003200211109820029
151020030201010
161120032003020119200311
17122004200312141210200312
18132005200313161311200313
191420050401414
20152006200414191512200415
211616
2220051713200517
2320051814200518
241919
2520062015200620
Sheet27
Cell Formulas
RangeFormula
A6=SEQUENCE(15)
F6=IF(ROWS($B$6:B6)=1,0,--(B6<>B5))
G6=IF(ROWS($B$6:B6)=1,0,COUNTIFS($F5:F$6,1))
H6=F6*(ROWS($B$6:B6)+G6)
J6=SEQUENCE(COUNT(F6:F20)+COUNTIFS(F6:F20,1))
K6=IF(ROWS($B$6:B6)=1,1,IF(SUM(--(J6=$H$6:$H$20)),"",J6-COUNTIFS($K5:K$6,"")))
L6=IFERROR(INDEX($B$6:$B$20,K6),"")
N6=ROW(INDIRECT("1:"&ROWS($B$6:B20)+SUM($F$6:$F$20)))
[/FONT]
 
Upvote 0

Forum statistics

Threads
1,214,935
Messages
6,122,337
Members
449,078
Latest member
skydd

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top