VBA to Choose Row Based on Two Criteria; One Exact Value and the Other Value is One of Several from a List on Another SheetVBA for checking rows and returning cells that match criteria to another sheetExcel find & replace cell contents based on contents of a list in another sheetExcel VBA— Error '424' object required issueConditional copy Excel File-2 data to excel file-1?Hide rows in sheet 1 and 2 based on cell value in sheet 1VBA, error while using lookupCopy Range Sheet1 Paste in Active Cell Sheet 2Excel VBA copy from one sheet to other sheets specific cells based on criteriaCopying Row from existing sheet based on date rangeHow can I copy range from sheet to sheet based on column value?

What language is Raven using for her attack in the new 52?

Did the Americans trade destroyers in the "destroyer deal" that they would later need themselves?

Should I bike or drive to work? (6.8 mi)

Filter search results by multiple filters in one operation

Telling manager project isn't worth the effort?

Does Wolfram Mathworld make a mistake describing a discrete probability distribution with a probability density function?

Do the books ever say oliphaunts aren’t elephants?

How to store my pliers and wire cutters on my desk?

How many oliphaunts died in all of the Lord of the Rings battles?

Move the outer key inward in an association

Is there a way to know the composition of a Team GO Rocket before going into the fight?

How can I say in Russian "I am not afraid to write anything"?

Why is the Apollo LEM ladder so far from the ground?

Why is it "on the inside" and not "in the inside"?

Is there a word to describe someone who is, or the state of being, content with hanging around others without interacting with them?

To find islands of 1 and 0 in matrix

Why does this RX-X lock not appear in Extended Events?

Will this creature from Curse of Strahd reappear after being banished?

What do you call a flexible diving platform?

Is there an antonym for "spicy" or "hot" regarding food?

Applying a Taylor series WITH RESPECT TO ... and AROUND...

Why does the Rust compiler not optimize code assuming that two mutable references cannot alias?

Must a song using the A minor scale begin or end with an Am chord? If not, how can I tell what the scale is?

Finding out if upgrading to a newer macOS version will cause issues?



VBA to Choose Row Based on Two Criteria; One Exact Value and the Other Value is One of Several from a List on Another Sheet


VBA for checking rows and returning cells that match criteria to another sheetExcel find & replace cell contents based on contents of a list in another sheetExcel VBA— Error '424' object required issueConditional copy Excel File-2 data to excel file-1?Hide rows in sheet 1 and 2 based on cell value in sheet 1VBA, error while using lookupCopy Range Sheet1 Paste in Active Cell Sheet 2Excel VBA copy from one sheet to other sheets specific cells based on criteriaCopying Row from existing sheet based on date rangeHow can I copy range from sheet to sheet based on column value?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















The code provided will currently copy a row and place it into another sheet if the code finds a row that contains both "OlsonJo" (Value=) in one cell and another cell that contains "UT-*" (Value Like (thx, S. Craner)).



I would like to modify this code to still include Value="OlsonJo" however the second criteria would be from a list. For example, if the row contains "OlsonJo" and the second criteria equals one of these in the list below (that resides on another sheet in the workbook).



UHS-Committee
UHS-Admin-Managing UHS Services
UHS-Admin-Meetings with staff
UHS-Admin-Communicating w/staff
UHS-Admin-Update Lab Test Formul
UHS-Admin-Write Procedure Manual
UHS-Admin-Candidate Interview
UHS-Admin-Consult Emp & Rev Qual
UHS-Admin-Scheduling functions
UHS-Admin-Strategic Lab Plan
UHS-Admin-Budget Planning
UHS-Admin-Equip Select & Acquis.
UHS-Admin-Test Select & Valid.
UHS-Sup/Ment Res/Fell-Sup Pa&Oth
UHS-Sup/Ment Res/Fell-1-1, Did
UHS-Sup/Ment Res/Fell-Sign O Case
UHS-Res/Fell-Interv ACGME pos
UHS-Res/Fell-Oth Act;Ad Res Prog
UHS-QA-Design/Analyze Lab QA Act
UHS-QA-Interpret Qual. Data/Rep
UHS-QA-Rev. Ext PT,QC,QM,& QAP
UHS-QA- Rev Investing Record lab events deviations
UHS-QA-Lab/Hospital Accred Act.
UHS-Autopsy-UHS Patient Autopsy
UHS-Analy-Clin Inform/Analy
UHS-Analy-Clin Inform EPIC Build
UHS-Analy-Proc.Improvem Act
UHS-Analy-Pop Hlth/Interd Coll
UHS-Analy-Clin Lab Util Mngt


then copy that row and place it in the designated sheet!



I have not been able to find a tutorial that includes pulling from a list of options. Again, thank you in advance for your time!



Sub FindOlsonUT() 
Dim i, LastRow
LastRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row 'this line finds the last row used in a sheet.

Sheets("Sheet2").Range("A2:M1000").ClearContents 'this line clears the contents of Sheet2 from A2 to M1000.

For i = 2 To LastRow
If Sheets("Sheet1").Cells(i, "D").Value = "OlsonJo" And Sheets("Sheet1").Cells(i, "H").Value Like "UT-*" Then 'the two criteria are in this line; exactly "OlsonJo" and contains "UT-"
Sheets("Sheet1").Cells(i, "D").EntireRow.Copy Destination:=Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1) 'destination is Sheet 2
End If
Next i
End Sub









share|improve this question


























  • Are you still testing column H for the UHS list?

    – GMalc
    Mar 26 at 20:13











  • Yes I am. Column H. Thanks!

    – Rick M
    Mar 26 at 20:16











  • can't you just change Sheets("Sheet1").Cells(i, "H").Value Like "UT-*" to Sheets("Sheet1").Cells(i, "H").Value Like "UHS-*"?

    – GMalc
    Mar 26 at 20:18











  • I wish... In column H of Sheet 1, there are more lines that begin with "UHS-" that don't match the examples I provided. Those specific tasks are the ones that need to be pulled from the larger data set. Thank you again!

    – Rick M
    Mar 26 at 20:33











  • How many of the other "UHS-" are there?

    – GMalc
    Mar 26 at 20:47

















0















The code provided will currently copy a row and place it into another sheet if the code finds a row that contains both "OlsonJo" (Value=) in one cell and another cell that contains "UT-*" (Value Like (thx, S. Craner)).



I would like to modify this code to still include Value="OlsonJo" however the second criteria would be from a list. For example, if the row contains "OlsonJo" and the second criteria equals one of these in the list below (that resides on another sheet in the workbook).



UHS-Committee
UHS-Admin-Managing UHS Services
UHS-Admin-Meetings with staff
UHS-Admin-Communicating w/staff
UHS-Admin-Update Lab Test Formul
UHS-Admin-Write Procedure Manual
UHS-Admin-Candidate Interview
UHS-Admin-Consult Emp & Rev Qual
UHS-Admin-Scheduling functions
UHS-Admin-Strategic Lab Plan
UHS-Admin-Budget Planning
UHS-Admin-Equip Select & Acquis.
UHS-Admin-Test Select & Valid.
UHS-Sup/Ment Res/Fell-Sup Pa&Oth
UHS-Sup/Ment Res/Fell-1-1, Did
UHS-Sup/Ment Res/Fell-Sign O Case
UHS-Res/Fell-Interv ACGME pos
UHS-Res/Fell-Oth Act;Ad Res Prog
UHS-QA-Design/Analyze Lab QA Act
UHS-QA-Interpret Qual. Data/Rep
UHS-QA-Rev. Ext PT,QC,QM,& QAP
UHS-QA- Rev Investing Record lab events deviations
UHS-QA-Lab/Hospital Accred Act.
UHS-Autopsy-UHS Patient Autopsy
UHS-Analy-Clin Inform/Analy
UHS-Analy-Clin Inform EPIC Build
UHS-Analy-Proc.Improvem Act
UHS-Analy-Pop Hlth/Interd Coll
UHS-Analy-Clin Lab Util Mngt


then copy that row and place it in the designated sheet!



I have not been able to find a tutorial that includes pulling from a list of options. Again, thank you in advance for your time!



Sub FindOlsonUT() 
Dim i, LastRow
LastRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row 'this line finds the last row used in a sheet.

Sheets("Sheet2").Range("A2:M1000").ClearContents 'this line clears the contents of Sheet2 from A2 to M1000.

For i = 2 To LastRow
If Sheets("Sheet1").Cells(i, "D").Value = "OlsonJo" And Sheets("Sheet1").Cells(i, "H").Value Like "UT-*" Then 'the two criteria are in this line; exactly "OlsonJo" and contains "UT-"
Sheets("Sheet1").Cells(i, "D").EntireRow.Copy Destination:=Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1) 'destination is Sheet 2
End If
Next i
End Sub









share|improve this question


























  • Are you still testing column H for the UHS list?

    – GMalc
    Mar 26 at 20:13











  • Yes I am. Column H. Thanks!

    – Rick M
    Mar 26 at 20:16











  • can't you just change Sheets("Sheet1").Cells(i, "H").Value Like "UT-*" to Sheets("Sheet1").Cells(i, "H").Value Like "UHS-*"?

    – GMalc
    Mar 26 at 20:18











  • I wish... In column H of Sheet 1, there are more lines that begin with "UHS-" that don't match the examples I provided. Those specific tasks are the ones that need to be pulled from the larger data set. Thank you again!

    – Rick M
    Mar 26 at 20:33











  • How many of the other "UHS-" are there?

    – GMalc
    Mar 26 at 20:47













0












0








0








The code provided will currently copy a row and place it into another sheet if the code finds a row that contains both "OlsonJo" (Value=) in one cell and another cell that contains "UT-*" (Value Like (thx, S. Craner)).



I would like to modify this code to still include Value="OlsonJo" however the second criteria would be from a list. For example, if the row contains "OlsonJo" and the second criteria equals one of these in the list below (that resides on another sheet in the workbook).



UHS-Committee
UHS-Admin-Managing UHS Services
UHS-Admin-Meetings with staff
UHS-Admin-Communicating w/staff
UHS-Admin-Update Lab Test Formul
UHS-Admin-Write Procedure Manual
UHS-Admin-Candidate Interview
UHS-Admin-Consult Emp & Rev Qual
UHS-Admin-Scheduling functions
UHS-Admin-Strategic Lab Plan
UHS-Admin-Budget Planning
UHS-Admin-Equip Select & Acquis.
UHS-Admin-Test Select & Valid.
UHS-Sup/Ment Res/Fell-Sup Pa&Oth
UHS-Sup/Ment Res/Fell-1-1, Did
UHS-Sup/Ment Res/Fell-Sign O Case
UHS-Res/Fell-Interv ACGME pos
UHS-Res/Fell-Oth Act;Ad Res Prog
UHS-QA-Design/Analyze Lab QA Act
UHS-QA-Interpret Qual. Data/Rep
UHS-QA-Rev. Ext PT,QC,QM,& QAP
UHS-QA- Rev Investing Record lab events deviations
UHS-QA-Lab/Hospital Accred Act.
UHS-Autopsy-UHS Patient Autopsy
UHS-Analy-Clin Inform/Analy
UHS-Analy-Clin Inform EPIC Build
UHS-Analy-Proc.Improvem Act
UHS-Analy-Pop Hlth/Interd Coll
UHS-Analy-Clin Lab Util Mngt


then copy that row and place it in the designated sheet!



I have not been able to find a tutorial that includes pulling from a list of options. Again, thank you in advance for your time!



Sub FindOlsonUT() 
Dim i, LastRow
LastRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row 'this line finds the last row used in a sheet.

Sheets("Sheet2").Range("A2:M1000").ClearContents 'this line clears the contents of Sheet2 from A2 to M1000.

For i = 2 To LastRow
If Sheets("Sheet1").Cells(i, "D").Value = "OlsonJo" And Sheets("Sheet1").Cells(i, "H").Value Like "UT-*" Then 'the two criteria are in this line; exactly "OlsonJo" and contains "UT-"
Sheets("Sheet1").Cells(i, "D").EntireRow.Copy Destination:=Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1) 'destination is Sheet 2
End If
Next i
End Sub









share|improve this question
















The code provided will currently copy a row and place it into another sheet if the code finds a row that contains both "OlsonJo" (Value=) in one cell and another cell that contains "UT-*" (Value Like (thx, S. Craner)).



I would like to modify this code to still include Value="OlsonJo" however the second criteria would be from a list. For example, if the row contains "OlsonJo" and the second criteria equals one of these in the list below (that resides on another sheet in the workbook).



UHS-Committee
UHS-Admin-Managing UHS Services
UHS-Admin-Meetings with staff
UHS-Admin-Communicating w/staff
UHS-Admin-Update Lab Test Formul
UHS-Admin-Write Procedure Manual
UHS-Admin-Candidate Interview
UHS-Admin-Consult Emp & Rev Qual
UHS-Admin-Scheduling functions
UHS-Admin-Strategic Lab Plan
UHS-Admin-Budget Planning
UHS-Admin-Equip Select & Acquis.
UHS-Admin-Test Select & Valid.
UHS-Sup/Ment Res/Fell-Sup Pa&Oth
UHS-Sup/Ment Res/Fell-1-1, Did
UHS-Sup/Ment Res/Fell-Sign O Case
UHS-Res/Fell-Interv ACGME pos
UHS-Res/Fell-Oth Act;Ad Res Prog
UHS-QA-Design/Analyze Lab QA Act
UHS-QA-Interpret Qual. Data/Rep
UHS-QA-Rev. Ext PT,QC,QM,& QAP
UHS-QA- Rev Investing Record lab events deviations
UHS-QA-Lab/Hospital Accred Act.
UHS-Autopsy-UHS Patient Autopsy
UHS-Analy-Clin Inform/Analy
UHS-Analy-Clin Inform EPIC Build
UHS-Analy-Proc.Improvem Act
UHS-Analy-Pop Hlth/Interd Coll
UHS-Analy-Clin Lab Util Mngt


then copy that row and place it in the designated sheet!



I have not been able to find a tutorial that includes pulling from a list of options. Again, thank you in advance for your time!



Sub FindOlsonUT() 
Dim i, LastRow
LastRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row 'this line finds the last row used in a sheet.

Sheets("Sheet2").Range("A2:M1000").ClearContents 'this line clears the contents of Sheet2 from A2 to M1000.

For i = 2 To LastRow
If Sheets("Sheet1").Cells(i, "D").Value = "OlsonJo" And Sheets("Sheet1").Cells(i, "H").Value Like "UT-*" Then 'the two criteria are in this line; exactly "OlsonJo" and contains "UT-"
Sheets("Sheet1").Cells(i, "D").EntireRow.Copy Destination:=Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1) 'destination is Sheet 2
End If
Next i
End Sub






excel vba






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 27 at 11:54







Rick M

















asked Mar 26 at 19:45









Rick MRick M

11 bronze badge




11 bronze badge















  • Are you still testing column H for the UHS list?

    – GMalc
    Mar 26 at 20:13











  • Yes I am. Column H. Thanks!

    – Rick M
    Mar 26 at 20:16











  • can't you just change Sheets("Sheet1").Cells(i, "H").Value Like "UT-*" to Sheets("Sheet1").Cells(i, "H").Value Like "UHS-*"?

    – GMalc
    Mar 26 at 20:18











  • I wish... In column H of Sheet 1, there are more lines that begin with "UHS-" that don't match the examples I provided. Those specific tasks are the ones that need to be pulled from the larger data set. Thank you again!

    – Rick M
    Mar 26 at 20:33











  • How many of the other "UHS-" are there?

    – GMalc
    Mar 26 at 20:47

















  • Are you still testing column H for the UHS list?

    – GMalc
    Mar 26 at 20:13











  • Yes I am. Column H. Thanks!

    – Rick M
    Mar 26 at 20:16











  • can't you just change Sheets("Sheet1").Cells(i, "H").Value Like "UT-*" to Sheets("Sheet1").Cells(i, "H").Value Like "UHS-*"?

    – GMalc
    Mar 26 at 20:18











  • I wish... In column H of Sheet 1, there are more lines that begin with "UHS-" that don't match the examples I provided. Those specific tasks are the ones that need to be pulled from the larger data set. Thank you again!

    – Rick M
    Mar 26 at 20:33











  • How many of the other "UHS-" are there?

    – GMalc
    Mar 26 at 20:47
















Are you still testing column H for the UHS list?

– GMalc
Mar 26 at 20:13





Are you still testing column H for the UHS list?

– GMalc
Mar 26 at 20:13













Yes I am. Column H. Thanks!

– Rick M
Mar 26 at 20:16





Yes I am. Column H. Thanks!

– Rick M
Mar 26 at 20:16













can't you just change Sheets("Sheet1").Cells(i, "H").Value Like "UT-*" to Sheets("Sheet1").Cells(i, "H").Value Like "UHS-*"?

– GMalc
Mar 26 at 20:18





can't you just change Sheets("Sheet1").Cells(i, "H").Value Like "UT-*" to Sheets("Sheet1").Cells(i, "H").Value Like "UHS-*"?

– GMalc
Mar 26 at 20:18













I wish... In column H of Sheet 1, there are more lines that begin with "UHS-" that don't match the examples I provided. Those specific tasks are the ones that need to be pulled from the larger data set. Thank you again!

– Rick M
Mar 26 at 20:33





I wish... In column H of Sheet 1, there are more lines that begin with "UHS-" that don't match the examples I provided. Those specific tasks are the ones that need to be pulled from the larger data set. Thank you again!

– Rick M
Mar 26 at 20:33













How many of the other "UHS-" are there?

– GMalc
Mar 26 at 20:47





How many of the other "UHS-" are there?

– GMalc
Mar 26 at 20:47












1 Answer
1






active

oldest

votes


















0














Taking the long way around the barn, but it works. Separated into subs. One sub looks for all rows with one of 8 or 9 different Value Like "UHS-



If Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Admin*" Or 
Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Sup/Ment Res/Fell-*" Or
Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Res/Fell-*" Or
Sheets("Sheet1").Cells(i, "H").Value Like "UHS-QA-*" Or
Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Sup*" Or
Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Autopsy-UHS Patient Autopsy" Or
Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Analy-*" Then


and copies those rows to Sheet2.



A second sub separates those tasks into different sheets by user.



Sub FindFiebelkornUHSAOA()
Dim i, LastRow
LastRow = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row 'this line finds the last row used in a sheet.
Sheets("Sheet3").Range("A2:M1000").ClearContents 'this line clears the contents of Sheet3 from A11 to M1000.
For i = 11 To LastRow
If Sheets("Sheet2").Cells(i, "D").Value = "FiebelkornKr" Then
Sheets("Sheet2").Cells(i, "D").EntireRow.Copy Destination:=Sheets("Sheet3").Range("A"
& Rows.Count).End(xlUp).Offset(1) '
End If
Next i
End Sub


Destination is Sheet 3 for rows that contain FiebelkornKr.



Here is the code that achieves the result I am looking for. Unfortunately, I have to apply this to 40-50 users.



Option Explicit
Sub PathDocsTimeSheets()
Call ExtractUHSAOA
Call FindFiebelkornUHSAOA
Call FindFiebelkornUHSClinCare
Call FindGreebonUHSAOA
Call FindGreebonUHSClinCare
End Sub

Sub ExtractUHSAOA()
Dim i, LastRow
LastRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row 'this line finds the last row used in a sheet.
Sheets("Sheet2").Range("A11:M1000").ClearContents f
Sheet2 from A11to M1000.
For i = 11 To LastRow
If Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Admin*" Or
Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Sup/Ment Res/Fell-*" Or
Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Res/Fell-*" Or
Sheets("Sheet1").Cells(i, "H").Value Like "UHS-QA-*" Or
Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Sup*" Or
Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Autopsy-UHS Patient Autopsy" Or
Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Analy-*" Then
Sheets("Sheet1").Cells(i, "D").EntireRow.Copy Destination:=Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1) 'destination is Sheet2
End If
Next i
End Sub


Sub FindFiebelkornUHSAOA()
Dim i, LastRow
LastRow = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row 'this line finds the last row used in a sheet.
Sheets("Sheet3").Range("A2:M1000").ClearContents 'this line clears the contents of Sheet3 from A11 to M1000.
For i = 11 To LastRow
If Sheets("Sheet2").Cells(i, "D").Value = "FiebelkornKr" Then
Sheets("Sheet2").Cells(i, "D").EntireRow.Copy Destination:=Sheets("Sheet3").Range("A"
& Rows.Count).End(xlUp).Offset(1) 'destination is Sheet 3
End If
Next i
End Sub

Sub FindFiebelkornUHSClinCare()
Dim i, LastRow
LastRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row 'this line finds the last row used in a sheet.
Sheets("Sheet4").Range("A11:M1000").ClearContents
For i = 11 To LastRow
If Sheets("Sheet1").Cells(i, "D").Value = "FiebelkornKr" And
Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Clin*" Then 'finds rows that have both "FiebelkornKr" exactly in column D and another cell that contains "UHS-Clin" in column H.
Sheets("Sheet1").Cells(i, "D").EntireRow.Copy Destination:=Sheets("Sheet4").Range("A"
& Rows.Count).End(xlUp).Offset(1) 'destination is Sheet4
End If
Next i
End Sub


Thank you for the suggestions and comments.






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55365158%2fvba-to-choose-row-based-on-two-criteria-one-exact-value-and-the-other-value-is%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Taking the long way around the barn, but it works. Separated into subs. One sub looks for all rows with one of 8 or 9 different Value Like "UHS-



    If Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Admin*" Or 
    Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Sup/Ment Res/Fell-*" Or
    Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Res/Fell-*" Or
    Sheets("Sheet1").Cells(i, "H").Value Like "UHS-QA-*" Or
    Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Sup*" Or
    Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Autopsy-UHS Patient Autopsy" Or
    Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Analy-*" Then


    and copies those rows to Sheet2.



    A second sub separates those tasks into different sheets by user.



    Sub FindFiebelkornUHSAOA()
    Dim i, LastRow
    LastRow = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row 'this line finds the last row used in a sheet.
    Sheets("Sheet3").Range("A2:M1000").ClearContents 'this line clears the contents of Sheet3 from A11 to M1000.
    For i = 11 To LastRow
    If Sheets("Sheet2").Cells(i, "D").Value = "FiebelkornKr" Then
    Sheets("Sheet2").Cells(i, "D").EntireRow.Copy Destination:=Sheets("Sheet3").Range("A"
    & Rows.Count).End(xlUp).Offset(1) '
    End If
    Next i
    End Sub


    Destination is Sheet 3 for rows that contain FiebelkornKr.



    Here is the code that achieves the result I am looking for. Unfortunately, I have to apply this to 40-50 users.



    Option Explicit
    Sub PathDocsTimeSheets()
    Call ExtractUHSAOA
    Call FindFiebelkornUHSAOA
    Call FindFiebelkornUHSClinCare
    Call FindGreebonUHSAOA
    Call FindGreebonUHSClinCare
    End Sub

    Sub ExtractUHSAOA()
    Dim i, LastRow
    LastRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row 'this line finds the last row used in a sheet.
    Sheets("Sheet2").Range("A11:M1000").ClearContents f
    Sheet2 from A11to M1000.
    For i = 11 To LastRow
    If Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Admin*" Or
    Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Sup/Ment Res/Fell-*" Or
    Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Res/Fell-*" Or
    Sheets("Sheet1").Cells(i, "H").Value Like "UHS-QA-*" Or
    Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Sup*" Or
    Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Autopsy-UHS Patient Autopsy" Or
    Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Analy-*" Then
    Sheets("Sheet1").Cells(i, "D").EntireRow.Copy Destination:=Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1) 'destination is Sheet2
    End If
    Next i
    End Sub


    Sub FindFiebelkornUHSAOA()
    Dim i, LastRow
    LastRow = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row 'this line finds the last row used in a sheet.
    Sheets("Sheet3").Range("A2:M1000").ClearContents 'this line clears the contents of Sheet3 from A11 to M1000.
    For i = 11 To LastRow
    If Sheets("Sheet2").Cells(i, "D").Value = "FiebelkornKr" Then
    Sheets("Sheet2").Cells(i, "D").EntireRow.Copy Destination:=Sheets("Sheet3").Range("A"
    & Rows.Count).End(xlUp).Offset(1) 'destination is Sheet 3
    End If
    Next i
    End Sub

    Sub FindFiebelkornUHSClinCare()
    Dim i, LastRow
    LastRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row 'this line finds the last row used in a sheet.
    Sheets("Sheet4").Range("A11:M1000").ClearContents
    For i = 11 To LastRow
    If Sheets("Sheet1").Cells(i, "D").Value = "FiebelkornKr" And
    Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Clin*" Then 'finds rows that have both "FiebelkornKr" exactly in column D and another cell that contains "UHS-Clin" in column H.
    Sheets("Sheet1").Cells(i, "D").EntireRow.Copy Destination:=Sheets("Sheet4").Range("A"
    & Rows.Count).End(xlUp).Offset(1) 'destination is Sheet4
    End If
    Next i
    End Sub


    Thank you for the suggestions and comments.






    share|improve this answer





























      0














      Taking the long way around the barn, but it works. Separated into subs. One sub looks for all rows with one of 8 or 9 different Value Like "UHS-



      If Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Admin*" Or 
      Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Sup/Ment Res/Fell-*" Or
      Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Res/Fell-*" Or
      Sheets("Sheet1").Cells(i, "H").Value Like "UHS-QA-*" Or
      Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Sup*" Or
      Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Autopsy-UHS Patient Autopsy" Or
      Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Analy-*" Then


      and copies those rows to Sheet2.



      A second sub separates those tasks into different sheets by user.



      Sub FindFiebelkornUHSAOA()
      Dim i, LastRow
      LastRow = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row 'this line finds the last row used in a sheet.
      Sheets("Sheet3").Range("A2:M1000").ClearContents 'this line clears the contents of Sheet3 from A11 to M1000.
      For i = 11 To LastRow
      If Sheets("Sheet2").Cells(i, "D").Value = "FiebelkornKr" Then
      Sheets("Sheet2").Cells(i, "D").EntireRow.Copy Destination:=Sheets("Sheet3").Range("A"
      & Rows.Count).End(xlUp).Offset(1) '
      End If
      Next i
      End Sub


      Destination is Sheet 3 for rows that contain FiebelkornKr.



      Here is the code that achieves the result I am looking for. Unfortunately, I have to apply this to 40-50 users.



      Option Explicit
      Sub PathDocsTimeSheets()
      Call ExtractUHSAOA
      Call FindFiebelkornUHSAOA
      Call FindFiebelkornUHSClinCare
      Call FindGreebonUHSAOA
      Call FindGreebonUHSClinCare
      End Sub

      Sub ExtractUHSAOA()
      Dim i, LastRow
      LastRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row 'this line finds the last row used in a sheet.
      Sheets("Sheet2").Range("A11:M1000").ClearContents f
      Sheet2 from A11to M1000.
      For i = 11 To LastRow
      If Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Admin*" Or
      Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Sup/Ment Res/Fell-*" Or
      Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Res/Fell-*" Or
      Sheets("Sheet1").Cells(i, "H").Value Like "UHS-QA-*" Or
      Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Sup*" Or
      Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Autopsy-UHS Patient Autopsy" Or
      Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Analy-*" Then
      Sheets("Sheet1").Cells(i, "D").EntireRow.Copy Destination:=Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1) 'destination is Sheet2
      End If
      Next i
      End Sub


      Sub FindFiebelkornUHSAOA()
      Dim i, LastRow
      LastRow = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row 'this line finds the last row used in a sheet.
      Sheets("Sheet3").Range("A2:M1000").ClearContents 'this line clears the contents of Sheet3 from A11 to M1000.
      For i = 11 To LastRow
      If Sheets("Sheet2").Cells(i, "D").Value = "FiebelkornKr" Then
      Sheets("Sheet2").Cells(i, "D").EntireRow.Copy Destination:=Sheets("Sheet3").Range("A"
      & Rows.Count).End(xlUp).Offset(1) 'destination is Sheet 3
      End If
      Next i
      End Sub

      Sub FindFiebelkornUHSClinCare()
      Dim i, LastRow
      LastRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row 'this line finds the last row used in a sheet.
      Sheets("Sheet4").Range("A11:M1000").ClearContents
      For i = 11 To LastRow
      If Sheets("Sheet1").Cells(i, "D").Value = "FiebelkornKr" And
      Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Clin*" Then 'finds rows that have both "FiebelkornKr" exactly in column D and another cell that contains "UHS-Clin" in column H.
      Sheets("Sheet1").Cells(i, "D").EntireRow.Copy Destination:=Sheets("Sheet4").Range("A"
      & Rows.Count).End(xlUp).Offset(1) 'destination is Sheet4
      End If
      Next i
      End Sub


      Thank you for the suggestions and comments.






      share|improve this answer



























        0












        0








        0







        Taking the long way around the barn, but it works. Separated into subs. One sub looks for all rows with one of 8 or 9 different Value Like "UHS-



        If Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Admin*" Or 
        Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Sup/Ment Res/Fell-*" Or
        Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Res/Fell-*" Or
        Sheets("Sheet1").Cells(i, "H").Value Like "UHS-QA-*" Or
        Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Sup*" Or
        Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Autopsy-UHS Patient Autopsy" Or
        Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Analy-*" Then


        and copies those rows to Sheet2.



        A second sub separates those tasks into different sheets by user.



        Sub FindFiebelkornUHSAOA()
        Dim i, LastRow
        LastRow = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row 'this line finds the last row used in a sheet.
        Sheets("Sheet3").Range("A2:M1000").ClearContents 'this line clears the contents of Sheet3 from A11 to M1000.
        For i = 11 To LastRow
        If Sheets("Sheet2").Cells(i, "D").Value = "FiebelkornKr" Then
        Sheets("Sheet2").Cells(i, "D").EntireRow.Copy Destination:=Sheets("Sheet3").Range("A"
        & Rows.Count).End(xlUp).Offset(1) '
        End If
        Next i
        End Sub


        Destination is Sheet 3 for rows that contain FiebelkornKr.



        Here is the code that achieves the result I am looking for. Unfortunately, I have to apply this to 40-50 users.



        Option Explicit
        Sub PathDocsTimeSheets()
        Call ExtractUHSAOA
        Call FindFiebelkornUHSAOA
        Call FindFiebelkornUHSClinCare
        Call FindGreebonUHSAOA
        Call FindGreebonUHSClinCare
        End Sub

        Sub ExtractUHSAOA()
        Dim i, LastRow
        LastRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row 'this line finds the last row used in a sheet.
        Sheets("Sheet2").Range("A11:M1000").ClearContents f
        Sheet2 from A11to M1000.
        For i = 11 To LastRow
        If Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Admin*" Or
        Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Sup/Ment Res/Fell-*" Or
        Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Res/Fell-*" Or
        Sheets("Sheet1").Cells(i, "H").Value Like "UHS-QA-*" Or
        Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Sup*" Or
        Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Autopsy-UHS Patient Autopsy" Or
        Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Analy-*" Then
        Sheets("Sheet1").Cells(i, "D").EntireRow.Copy Destination:=Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1) 'destination is Sheet2
        End If
        Next i
        End Sub


        Sub FindFiebelkornUHSAOA()
        Dim i, LastRow
        LastRow = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row 'this line finds the last row used in a sheet.
        Sheets("Sheet3").Range("A2:M1000").ClearContents 'this line clears the contents of Sheet3 from A11 to M1000.
        For i = 11 To LastRow
        If Sheets("Sheet2").Cells(i, "D").Value = "FiebelkornKr" Then
        Sheets("Sheet2").Cells(i, "D").EntireRow.Copy Destination:=Sheets("Sheet3").Range("A"
        & Rows.Count).End(xlUp).Offset(1) 'destination is Sheet 3
        End If
        Next i
        End Sub

        Sub FindFiebelkornUHSClinCare()
        Dim i, LastRow
        LastRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row 'this line finds the last row used in a sheet.
        Sheets("Sheet4").Range("A11:M1000").ClearContents
        For i = 11 To LastRow
        If Sheets("Sheet1").Cells(i, "D").Value = "FiebelkornKr" And
        Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Clin*" Then 'finds rows that have both "FiebelkornKr" exactly in column D and another cell that contains "UHS-Clin" in column H.
        Sheets("Sheet1").Cells(i, "D").EntireRow.Copy Destination:=Sheets("Sheet4").Range("A"
        & Rows.Count).End(xlUp).Offset(1) 'destination is Sheet4
        End If
        Next i
        End Sub


        Thank you for the suggestions and comments.






        share|improve this answer













        Taking the long way around the barn, but it works. Separated into subs. One sub looks for all rows with one of 8 or 9 different Value Like "UHS-



        If Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Admin*" Or 
        Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Sup/Ment Res/Fell-*" Or
        Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Res/Fell-*" Or
        Sheets("Sheet1").Cells(i, "H").Value Like "UHS-QA-*" Or
        Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Sup*" Or
        Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Autopsy-UHS Patient Autopsy" Or
        Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Analy-*" Then


        and copies those rows to Sheet2.



        A second sub separates those tasks into different sheets by user.



        Sub FindFiebelkornUHSAOA()
        Dim i, LastRow
        LastRow = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row 'this line finds the last row used in a sheet.
        Sheets("Sheet3").Range("A2:M1000").ClearContents 'this line clears the contents of Sheet3 from A11 to M1000.
        For i = 11 To LastRow
        If Sheets("Sheet2").Cells(i, "D").Value = "FiebelkornKr" Then
        Sheets("Sheet2").Cells(i, "D").EntireRow.Copy Destination:=Sheets("Sheet3").Range("A"
        & Rows.Count).End(xlUp).Offset(1) '
        End If
        Next i
        End Sub


        Destination is Sheet 3 for rows that contain FiebelkornKr.



        Here is the code that achieves the result I am looking for. Unfortunately, I have to apply this to 40-50 users.



        Option Explicit
        Sub PathDocsTimeSheets()
        Call ExtractUHSAOA
        Call FindFiebelkornUHSAOA
        Call FindFiebelkornUHSClinCare
        Call FindGreebonUHSAOA
        Call FindGreebonUHSClinCare
        End Sub

        Sub ExtractUHSAOA()
        Dim i, LastRow
        LastRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row 'this line finds the last row used in a sheet.
        Sheets("Sheet2").Range("A11:M1000").ClearContents f
        Sheet2 from A11to M1000.
        For i = 11 To LastRow
        If Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Admin*" Or
        Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Sup/Ment Res/Fell-*" Or
        Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Res/Fell-*" Or
        Sheets("Sheet1").Cells(i, "H").Value Like "UHS-QA-*" Or
        Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Sup*" Or
        Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Autopsy-UHS Patient Autopsy" Or
        Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Analy-*" Then
        Sheets("Sheet1").Cells(i, "D").EntireRow.Copy Destination:=Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1) 'destination is Sheet2
        End If
        Next i
        End Sub


        Sub FindFiebelkornUHSAOA()
        Dim i, LastRow
        LastRow = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row 'this line finds the last row used in a sheet.
        Sheets("Sheet3").Range("A2:M1000").ClearContents 'this line clears the contents of Sheet3 from A11 to M1000.
        For i = 11 To LastRow
        If Sheets("Sheet2").Cells(i, "D").Value = "FiebelkornKr" Then
        Sheets("Sheet2").Cells(i, "D").EntireRow.Copy Destination:=Sheets("Sheet3").Range("A"
        & Rows.Count).End(xlUp).Offset(1) 'destination is Sheet 3
        End If
        Next i
        End Sub

        Sub FindFiebelkornUHSClinCare()
        Dim i, LastRow
        LastRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row 'this line finds the last row used in a sheet.
        Sheets("Sheet4").Range("A11:M1000").ClearContents
        For i = 11 To LastRow
        If Sheets("Sheet1").Cells(i, "D").Value = "FiebelkornKr" And
        Sheets("Sheet1").Cells(i, "H").Value Like "UHS-Clin*" Then 'finds rows that have both "FiebelkornKr" exactly in column D and another cell that contains "UHS-Clin" in column H.
        Sheets("Sheet1").Cells(i, "D").EntireRow.Copy Destination:=Sheets("Sheet4").Range("A"
        & Rows.Count).End(xlUp).Offset(1) 'destination is Sheet4
        End If
        Next i
        End Sub


        Thank you for the suggestions and comments.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 27 at 13:22









        Rick MRick M

        11 bronze badge




        11 bronze badge





















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55365158%2fvba-to-choose-row-based-on-two-criteria-one-exact-value-and-the-other-value-is%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript