title: Excel Macro to Loop Through Cells, If Value is True output data to another worksheet
body: <p>I'm working on a project where users will be going through a list of 'tests' and checking off whether the test passed or failed.  If the test fails, they check the 'fail' box in the second column and record notes as to why that test failed.  The setup looks like this:</p>
  
  <p><a href="http://imgur.com/a/5Akzj" rel="nofollow">Worksheet 1 - Top Image</a></p>
  
  <p>I need to program a macro so that when the user finishes the 'tests' and clicks the 'Generate Report' button, it compiles a summary of the failed tests and the associated notes on another worksheet, such as this:</p>
  
  <p><a href="http://imgur.com/a/5Akzj" rel="nofollow">Worksheet 2 - Summary of Failed Tests (Bottom Image)</a></p>
  
  <p>I have a development background but am not familiar with the syntax for Excel macros.  I've done a little digging around but figured I'd ask here first.  Essentially I need to run a loop through all the cells in the 'fail' column.  Everytime I hit a 'true' value, output the contents of the notes in the cell to the right of it and the name of the test two cells to the left onto the other worksheet.  Let me know how you'd approach this and what type of function you'd you - I greatly appreciate your help!</p>
  
  <p><strong>UPDATE:  ANSWER HERE:</strong></p>
  
  <p>I created 3 named ranges: tests, fails, and notes. It's easy, just select the list of tests (excluding the header) and type tests in the address box. Named range created. Do the same for your Fails and your Notes.
  Then, on page 2:</p>
  
  <pre><code>[A3]=INDEX(tests,MATCH(TRUE,fails,0))
  [B3]=INDEX(notes,MATCH(TRUE,fails,0))
  [A4]=IFERROR(INDEX(OFFSET(tests,MATCH(A3,tests,0),0),MATCH(TRUE,OFFSET(fails,MATCH(A3,tests,0),0),0)),"")
  [B4]=IFERROR(INDEX(OFFSET(notes,MATCH(A3,tests,0),0),MATCH(TRUE,OFFSET(fails,MATCH(A3,tests,0),0),0)),"")
  </code></pre>
  
  <p>(copy A4 and B4 down as far as you need it.)</p>