You are here:

Excel/Re-arranging the data


Hi Bob,

I have certain data in one of my sheet and I need to reduce it vertically based on some conditions.

Please consider the below example:
If Flag=1
Copy the row.
Else If Flag = 0 AND (TS# = 2 OR TS# = 3)
         Copy the row
Else Donít copy the row

Challenge is to make sure that data is vertically reduced and we are not left with any empty rows.
In below example Input table as 42 rows but we have reduce them to 22 rows based on above logic.

Please note I want to build this example with formulas/array not Macro.!152&authkey=!AJ_OiY3HqFn3cy8

Toughie to do by formulas, but I got it.
You need a helper column which you can hide. I used column O.
In O7 enter this formula via ctrl+shift+enter:

in F7 enter:
fill this right to column H and down as far as you want (after row 28 the IFERROR part will show the null string (effectively showing nothing)

Hide column O.
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here


All Answers

Answers by Expert:

Ask Experts


Bob Umlas


I`m a Microsoft Excel MVP (Most Valuable Professional) and have been since the inception of the program in 1995. I can answer every kind of Excel question except: API, Importing/exporting to other programs (powerpoint, word,...) Also check out my in-person training link at


Worked with MS Excel since version 0.99 (on the Mac!). Was contributing editor to Excellence Magazine, having written >300 articles. John Walkenbach said of me "I finally met someone who knows as much about Excel as I do."

Excellence, The Expert, Microsoft

BA in math, Hofstra University, 1965

Awards and Honors
Led sessions for the Convergence 2004-2006 seminar on Excel tips & tricks

©2017 All rights reserved.