## Recommended Posts

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

##### Share on other sites

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,
=SUM(1(B1<\$B\$1:\$B\$50))+1+IF(ROW(B1)-ROW(\$B\$1)=0,0,SUM(1(B1=OFFSET(\$B\$1,0,0,INDEX(ROW(B1)-ROW(\$B\$1)+1,1)-1,1))))

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

##### Share on other sites

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,

=SUM(1(B1<\$B\$1:\$B\$50))+1+IF(ROW(B1)-ROW(\$B\$1)=0,0,SUM(1(B1=OFFSET(\$B\$1,0,0,INDEX(ROW(B1)-ROW(\$B\$1)+1,1)-1,1))))

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

It is very smart answer !!!! Congrates

##### Share on other sites

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,

=SUM(1(B1<\$B\$1:\$B\$50))+1+IF(ROW(B1)-ROW(\$B\$1)=0,0,SUM(1(B1=OFFSET(\$B\$1,0,0,INDEX(ROW(B1)-ROW(\$B\$1)+1,1)-1,1))))

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

I dont understand this but it looks good

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account. ×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×

• ### Similar Content

• Quick question for you groovy excel ppl out there. I'm working with a vendor and need to calculate the discount and/or increase. I know there is a simple excel formula I can use. Just looking for a tip for it.
Thanks!
• By Steve
Question from Reader - Email Form

Hi Tom,

Ouch. I know how it feels losing a days worth of work. The worst part is when you have to recreate what you've already done.

To answer your question, when you found the Entry "OutlookSecureTempFolder" what was the path in the DATA column? I assume you reviewed this post here to find it. It looks like you found the registry key entry so your more than 1/2 way there. Find that key again and you should have the path to your OLK folder and your Excel should be sitting there.

Now the path might be a bit confusing because with Outlook 2007, there actually is "NOT" an OLK folder. For instance, on my XP/Outlook 2007 install, my OLK folder or "Temp Outlook Folder" / "OutlookSecureTempFolder" is:

"c:\Documents and Settings\mrgroove\Local Settings\Temporary Internet Files\Content.Outlook\4V32TZLP"

So if you look on your box you will find what your looking for in the "Content.Outlook" folder. Take a look there and your golden.

Let me know how this works for you!

• Office Excel 2011 - Protect worksheet or workbook - I have protected the worksheet by a password but find I still can copy and past into a new worksheet and then I can change things arround. How can I stop someone being able to change or delete things.
• By Austin
Beatrice writes:

I have a question, I know how to do a data validation drop down but I need the one list with two buttons in the same cell and a range of years.Do you know how to do this?
I work for the school district and they need a particular calendar. They have a cell where you can list the year but it list whole number with a range of 1999 to 2999 and has two buttons.... one to go up in years and one to go lower... Hope this makes sense
• By Abby
I have a list containing dates of birth going from cell A1 to cell A1765 and need to calculate the ages.
So far I have a row of formulas B1 to B1765 subtracting the dates of birth from todays date. Then I have a row of formulas from C1 to C1765 dividing the number of days by 365 with the cells formatted to show no decimal places to give the number of years.
I now need to calculate the months and years so for example the age of someone born on 01/12/1980 would be 31 years 2 months and 19 days
I am thinking of taking the results from column C multiplying them by 365 then subtracting them from the total number of days then dividing by 30 for number of months but this is getting complicated and it doesnt account for months that have more or less than 30 days.
• ### Who's Online   0 Members, 0 Anonymous, 18 Guests(See full list)

There are no registered users currently online