Meeting And/Or Criteria with an If Statement<p align=left><font face=Arial size=2>Hello,</font></p> <p align=left> </p> <p align=left>I have a spreadsheet in Excel 2003 with two columns of data.  Column A is labeled &quot;Work&quot; and Column B is labeled &quot;Type of Work&quot;.  The macro that I have activates cell A2 and implements a Do While Loop to scroll through each row on the spreadsheet that contains data.  Inside this Do While Loop, the macro is looking for rows that meet certain criteria in columns A and B.  Column A must equal the variable work, which is defined by the user using an input box and coumn B must either contain the text &quot;PM&quot; or &quot;MP&quot;.  I am trying to implement an If Then statement that looks for rows that contain the variable work in column A and either &quot;PM&quot; or &quot;MP&quot; in column B, but I don't know how to specify the or just for column B.  How would I go about doing this?</p> <p align=left> </p> <p align=left>Thanks.   </p>© 2009 Microsoft Corporation. All rights reserved.Wed, 10 Dec 2008 23:25:30 Zd9d42144-6598-493d-a361-11083b129c8dhttp://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/d9d42144-6598-493d-a361-11083b129c8d#d9d42144-6598-493d-a361-11083b129c8dhttp://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/d9d42144-6598-493d-a361-11083b129c8d#d9d42144-6598-493d-a361-11083b129c8dEazy-Dhttp://social.msdn.microsoft.com/Profile/en-US/?user=Eazy-DMeeting And/Or Criteria with an If Statement<p align=left><font face=Arial size=2>Hello,</font></p> <p align=left> </p> <p align=left>I have a spreadsheet in Excel 2003 with two columns of data.  Column A is labeled &quot;Work&quot; and Column B is labeled &quot;Type of Work&quot;.  The macro that I have activates cell A2 and implements a Do While Loop to scroll through each row on the spreadsheet that contains data.  Inside this Do While Loop, the macro is looking for rows that meet certain criteria in columns A and B.  Column A must equal the variable work, which is defined by the user using an input box and coumn B must either contain the text &quot;PM&quot; or &quot;MP&quot;.  I am trying to implement an If Then statement that looks for rows that contain the variable work in column A and either &quot;PM&quot; or &quot;MP&quot; in column B, but I don't know how to specify the or just for column B.  How would I go about doing this?</p> <p align=left> </p> <p align=left>Thanks.   </p>Sun, 03 Aug 2008 18:22:02 Z2008-08-03T18:22:02Zhttp://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/d9d42144-6598-493d-a361-11083b129c8d#cc361202-3a97-43c6-a385-370703f0126ehttp://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/d9d42144-6598-493d-a361-11083b129c8d#cc361202-3a97-43c6-a385-370703f0126ecrdotlinhttp://social.msdn.microsoft.com/Profile/en-US/?user=crdotlinMeeting And/Or Criteria with an If Statement<p>Using AdvanedFilter is recommended.</p> <p align=left><font face=Arial size=2></font> </p> <p align=left><font face=Courier><span style="color:#00008f"> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Snippet</span></div> <p align=left><font face=Courier><span style="color:#00008f">Sub</span> myAdFilter()<br><span style="color:#00008f">Dim</span> srSht <span style="color:#00008f">As</span> Worksheet<br><span style="color:#00008f">Dim</span> dtSht <span style="color:#00008f">As</span> Worksheet<br>    <span style="color:#00008f">Set</span> srSht = Sheets(&quot;Sheet1&quot;)<br>    <span style="color:#00008f">Set</span> dtSht = Sheets(&quot;Sheet2&quot;)<br>    dtSht.Cells.ClearContents<br>    <span style="color:#00008f">With</span> srSht<br>        .Columns(&quot;A:B&quot;).AdvancedFilter Action:=xlFilterCopy, _<br>            CriteriaRange:=.Range(&quot;H1:I3&quot;), CopyToRange:=dtSht.Range(&quot;A1&quot;), _<br>            Unique:=<span style="color:#00008f">False</span><br>    <span style="color:#00008f">End</span> <span style="color:#00008f">With</span><br>    dtSht.Activate<br><span style="color:#00008f">End</span> <span style="color:#00008f">Sub</span></font></p></div></div> <p align=left> </p></span><span style="color:#00008f"></span></font> <p></p> <p>here is the example.</p> <p align=left><a title="http://www.box.net/shared/uqtw80w8wc" href="http://www.box.net/shared/uqtw80w8wc">http://www.box.net/shared/uqtw80w8wc</a></p> <p align=left> </p>Mon, 04 Aug 2008 02:52:33 Z2008-08-04T02:52:33Zhttp://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/d9d42144-6598-493d-a361-11083b129c8d#aa9d4431-da67-4cdb-a08a-94a53e8b9f67http://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/d9d42144-6598-493d-a361-11083b129c8d#aa9d4431-da67-4cdb-a08a-94a53e8b9f67Eazy-Dhttp://social.msdn.microsoft.com/Profile/en-US/?user=Eazy-DMeeting And/Or Criteria with an If Statement<p align=left><font face=Arial size=2>I want the macro to copy the entire row containing the cells that meet this critera.  Can this still be done with AdvancedFilter?</font></p>Wed, 06 Aug 2008 21:22:31 Z2008-08-06T21:22:31Zhttp://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/d9d42144-6598-493d-a361-11083b129c8d#7ed7c450-012a-48d9-b673-39bf99b0ab4dhttp://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/d9d42144-6598-493d-a361-11083b129c8d#7ed7c450-012a-48d9-b673-39bf99b0ab4dcrdotlinhttp://social.msdn.microsoft.com/Profile/en-US/?user=crdotlinMeeting And/Or Criteria with an If Statement<p>Yes, it do be done with AdvancedFilter.</p> <p align=left>check out the code below...</p> <p align=left><font face=Arial size=2></font> </p> <p align=left><font face=Courier><span style="color:#00008f"> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Snippet</span></div> <p align=left><font face=Courier><span style="color:#00008f">Sub</span> myAdFilter()<br><span style="color:#00008f">Dim</span> srSht <span style="color:#00008f">As</span> Worksheet<br><span style="color:#00008f">Dim</span> dtSht <span style="color:#00008f">As</span> Worksheet<br>    <span style="color:#00008f">Set</span> srSht = Sheets(&quot;Sheet1&quot;)<br>    <span style="color:#00008f">Set</span> dtSht = Sheets(&quot;Sheet2&quot;)<br>    dtSht.Cells.ClearContents<br>    <span style="color:#008f00">'This example is assuming that</span><br>    <span style="color:#008f00">'1. the data table's lefttop cell is located at A1cell</span><br>    <span style="color:#008f00">'2. the criteria range is located at H1:I3</span><br>    <span style="color:#00008f">With</span> srSht<br>        .Range(&quot;a1&quot;).CurrentRegion.AdvancedFilter Action:=xlFilterCopy, _<br>            CriteriaRange:=.Range(&quot;H1:I3&quot;), CopyToRange:=dtSht.Range(&quot;A1&quot;), _<br>            Unique:=<span style="color:#00008f">False</span><br>    <span style="color:#00008f">End</span> <span style="color:#00008f">With</span><br>    dtSht.Activate<br><span style="color:#00008f">End</span> <span style="color:#00008f">Sub</span></font></p> <p align=left> </p></div></div> <p align=left> </p></span><span style="color:#00008f"></span></font> <p></p> <p>and example is here</p> <p align=left><a title="http://www.box.net/shared/com7vfvw4c" href="http://www.box.net/shared/com7vfvw4c">http://www.box.net/shared/com7vfvw4c</a></p> <p align=left> </p> <p align=left>any problems, please email an example to  <a title="mailto:mnw0307@gmail.com" href="mailto:mnw0307@gmail.com">mnw0307@gmail.com</a></p> <p align=left> </p>Thu, 07 Aug 2008 01:50:06 Z2008-08-07T01:50:06Z