• 1
Abby

Help needed with Excel macros

Question

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 this post


Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 4

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 this post


Link to post
Share on other sites
  • 0

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 this post


Link to post
Share on other sites
  • 0

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Similar Content

    • 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!
  • Who's Online   0 Members, 0 Anonymous, 10 Guests (See full list)

    There are no registered users currently online