login about faq

I have column B with 200 rows of true / false

I am trying to write a macro that will search column B from the top and when it finds the first true it will copy the contents from that row in column A and paste them to D1

Then I want to do the same thing in D2 but searching for the second true then in D3 searching for the third true.

e.g. If the first True is in cell B50 then I want cell D1 to display the contents of cell A50

If the second True is further down say in B75 I want cell D2 to display the contents of cell A75

If the third True is in cell B150 then I want cell D3 to display the contents of cell A150

It doesn’t matter if there are more than 3 True's I only need to find the first 3 wherever they are in column B

asked Mar 20 '12 at 10:53

Abby's gravatar image


You can actually do what you want with an array formula rather than a macro.

Presuming that your true false column starts at the top of column B in Cell B1 you need to copy and paste this into Cell C1,

Now click on the formula bar and press Ctrl+Shift+Enter. The formula should now be in array brackets { }. This is important because without using CTRL+SHIFT+ENTER, you will get incorrect results.

Copy the formula down your range.

This ranks your TRUE's and FALSE's, giving TRUE values the lower #'s and FALSE values higher ones. So your first TRUE is ranked 1, 2nd TRUE is ranked 2, etc...

The rankings will automatically update if you change any TRUE to FALSE, or FALSE to TRUE

Now you can use INDEX/MATCH to get the data:

Copy and paste this into Cell D1 =INDEX($A$1:$C$50,MATCH(SMALL($C$1:$C$50,1),$C$1:$C$50,0),1)

Copy and paste this into Cell D2 =INDEX($A$1:$C$50,MATCH(SMALL($C$1:$C$50,2),$C$1:$C$50,0),1)

Copy and paste this into Cell D3 =INDEX($A$1:$C$50,MATCH(SMALL($C$1:$C$50,3),$C$1:$C$50,0),1)

This searches for the first, the second, and the third smallest number in Column C (1, 2, 3) and returns the value from the corresponding row in Column A.

If you are already using column C then you can put the array formula in any column but you will need to alter the formulas in D1, 2 and 3 to point to your chosen location of the array formula.

I believe this method is simpler than writing a macro and you can easily update it to look for more than the first 3 true values if needed


answered Mar 20 '12 at 16:01

Simon%20H's gravatar image

Simon H

It is very smart answer !!!! Congrates

(Apr 07 '12 at 15:40) dep dep's gravatar image

I dont understand this but it looks good

(Apr 17 '12 at 17:29) Jezzer Jezzer's gravatar image
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:
    [text](http://url.com/ "title")
  • image:
    ![alt text](/path/img.jpg "title")
  • numbered list:
    1. Foo
    2. Bar
  • Code:
    • Within a paragraph:
      surround code with grave accents (backticks)
    • Code snippet:
      Select the text and use the button on the icon of zeros and ones
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: Mar 20 '12 at 10:53

Seen: 2,019 times

Last updated: Apr 17 '12 at 17:29

groovyAnswers © 2007 - 2011 All Rights Reserved | Privacy | Contact