Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automatically insert a blank row after a group of data

I have created a sample table below that is similar-enough to my table in excel that it should serve to illustrate the question. I want to simply add a row after each distinct datum in column1 (simplest way, using excel, thanks).

_

CURRENT TABLE:

column1   |   column2   |  column3
----------------------------------
  A       |     small   |  blue
  A       |     small   |  orange
  A       |     small   |  yellow
  B       |     med     |  yellow
  B       |     med     |  blue
  C       |     large   |  green
  D       |     large   |  green
  D       |     small   |  pink

_

DESIRED TABLE

Note: the blank row after each distinct column1

column1   |   column2   |  column3
----------------------------------
  A       |     small   |  blue
  A       |     small   |  orange
  A       |     small   |  yellow

  B       |     med     |  yellow
  B       |     med     |  blue

  C       |     large   |  green

  D       |     large   |  green
  D       |     small   |  pink
like image 273
Ben Avatar asked Mar 14 '13 18:03

Ben


3 Answers

This does exactly what you are asking, checks the rows, and inserts a blank empty row at each change in column A:

sub AddBlankRows()
'
dim iRow as integer, iCol as integer
dim oRng as range

set oRng=range("a1")

irow=oRng.row
icol=oRng.column

do 
'
if cells(irow+1, iCol)<>cells(irow,iCol) then
    cells(irow+1,iCol).entirerow.insert shift:=xldown
    irow=irow+2
else
    irow=irow+1
end if
'
loop while not cells (irow,iCol).text=""
'
end sub

I hope that gets you started, let us know!

Philip

like image 130
Our Man in Bananas Avatar answered Nov 12 '22 12:11

Our Man in Bananas


Select your array, including column labels, DATA > Outline -Subtotal, At each change in: column1, Use function: Count, Add subtotal to: column3, check Replace current subtotals and Summary below data, OK.

Filter and select for Column1, Text Filters, Contains..., Count, OK. Select all visible apart from the labels and delete contents. Remove filter and, if desired, ungroup rows.

like image 39
pnuts Avatar answered Nov 12 '22 14:11

pnuts


This won't work if the data is not sequential (1 2 3 4 but 5 7 3 1 5) as in that case you can't sort it.

Here is how I solve that issue for me:

Column A initial data that needs to contain 5 rows between each number - 5 4 6 8 9

Column B - 1 2 3 4 5 (final number represents the number of empty rows that you need to be between numbers in column A) copy-paste 1-5 in column B as long as you have numbers in column A.

Jump to D column, in D1 type 1. In D2 type this formula - =IF(B2=1,1+D1,D1) Drag it to the same length as column B.

Back to Column C - at C1 cell type this formula - =IF(B1=1,INDIRECT("a"&(D1)),""). Drag it down and we done. Now in column C we have same sequence of numbers as in column A distributed separately by 4 rows.

like image 1
Arunas Avatar answered Nov 12 '22 12:11

Arunas