VBA Code - Search keywords and paste different results to different sheets

JoeDelcambre

New Member
Joined
Feb 20, 2022
Messages
16
Office Version
  1. 365
Platform
  1. Windows
I am trying to write two macros to find two sets of keywords on Sheet 3 and paste entire rows to either Sheets 4, 5, or 6, depending on the results.


First, I'll create Sheets 4, 5, and 6 for the results of the macro.

First query/macro:
Search Sheet 3 only.
Sheet 4 can only have terms from "Set 1" (listed below). If the query finds a row where there are words from only Set 1, results should be pasted on Sheet 4.
If the query finds a row with words from both Sets 1 and 2, those lines should pasted into Sheet 6.

The keywords are:
Set 1
"abc"
"def"
"xyz"


Second query/macro:
Search Sheet 3 only.
Sheet 5 can only have terms from "Set 2". If results from this query finds a row with only words from Set 2, results should be pasted on Sheet 5. If the query finds a row with words from both Sets 1 and 2, those lines should pasted into Sheet 6.

Set 2
"apple"
"banana"
"orange"


Sheet 6 can only have lines with at least one term from both Sets 1 and 2.

Any and all help is greatly appreciated.

macro tests2.xlsm
ABCDEFGHIJKLMN
1IDMust_PayFundedAgencyDirectorate_IDDivision_IDAcq_PackageOS Amount_Paid Amount_Owed Date_UpdatedStart_DateEnd_DateUpdated_By
2ABC568yesyesUSMCJ6IODUSMC-Package 789vista$ 4,000.00$ 10,000.0012/25/20212/5/20202/1/2022John Smith
3SDJ4478yesnoUSMCJ6CSDUSMC-Package 789XP$ 2,000.00$ 12,000.0011/15/20212/5/20202/2/2022Jane Doe
4LIU9898noyesUSAJ3CSDUSA-Package 3398JTTP4 Windows 7 HWLM$ 3,500.00$ 6,500.003/2/20213/1/20212/3/2022John Doe
5HBR5454yesnoUSAJ3SDDUSA-Package 3398JWin 10$ 2,500.00$ 7,500.006/15/20214/1/20212/4/2022Jane Smith
6NHRI2347yesyesUSNJ2EODUSN-Package 923Windows 10$ 1,200.00$ 10,000.001/22/20225/5/20202/5/2022Jane Smith
7NCUR2458noyesUSCGJ6CIOUSCG-Package 3287Vista$ 6,500.00$ 8,000.001/6/20229/4/20202/6/2022Jane Smith
8LKJ2147noyesUSAFJ3CSDUSAF-Package 776534Win XP$ 2,100.00$ 3,500.007/25/20217/5/20212/7/2022Jane Smith
9POI6698yesnoUSAJ4IODUSA-Package 3398Jwin xp$ 9,800.00$ 12,000.009/2/20214/16/20202/8/2022Jane Smith
10ABCS987nonoUSAFJ1SDDUSAF-Package 776534TTP4 Windows 7 HWLM$ 7,400.00$ 8,000.006/6/20213/1/20212/9/2022Joe Doe
11SMN3298noyesUSSFS4CSDUSSF-Package 2312Windows 7$ 6,500.00$ 9,500.009/22/20217/5/20212/10/2022Joe Doe
12LED8852nonoUSSFS4IODUSSF-Package 2312Windows 10$ 3,500.00$ 3,500.0011/2/20216/7/20202/11/2022John Smith
13LMN326yesyesUSCGS2CSDUSCG-Package 3287Windows XP$ 2,100.00$ 2,500.007/9/20213/1/20212/12/2022John Doe
14WDC589noyesUSNS6CIOUSN-Package 923Win 7$ 1,750.00$ 8,700.002/1/202211/9/20202/13/2022Jane Doe
15VFD365yesyesUSNS6CIOUSN-Package 923Win xp$ 630.00$ 6,500.003/6/20213/25/20202/14/2022Jane Smith
16CVF127yesyesUSMCS3CIOUSMC-Package 78974BBN win 7 TTP77$ 2,500.00$ 3,500.0012/1/20211/6/20212/15/2022Jane Smith
17CVRF9863yesnoUSNJ2SDDUSN-Package 923windows 7$ 7,800.00$ 7,800.002/2/20229/7/20202/16/2022Jane Smith
18MMLK145nonoUSMCJ4IODUSMC-Package 789windows 10$ 9,800.00$ 9,800.003/8/20213/19/20212/17/2022John Doe
19EWD441yesyesUSAFS4CSDUSAF-Package 776534windows XP$ 1,200.00$ 4,500.008/5/20217/7/20202/18/2022John Doe
20RRB2285nonoUSAFS5CSDUSAF-Package 776534Windows 7$ 3,200.00$ 4,500.009/5/20219/3/20202/19/2022John Doe
21ABC568yesorangeabcJ6xyzUSMC-Package 789vista$ 4,000.00$ 10,000.0012/25/20212/5/20202/1/2022John Smith
22SDJ4478yesorangeUSMCJ6CSDUSMC-Package 789XP$ 2,000.00$ 12,000.0011/15/20212/5/20202/2/2022Jane Doe
23LIU9898noyesUSAJ3xyzUSA-Package 3398JWindows 7$ 3,500.00$ 6,500.003/2/20213/1/20212/3/2022John Doe
24HBR5454yesnoabcJ3CSDUSA-Package 3398JWin 10$ 2,500.00$ 7,500.006/15/20214/1/20212/4/2022Jane Smith
25NHRI2347yesbananaUSNJ2EODUSN-Package 923Windows 10$ 1,200.00$ 10,000.001/22/20225/5/20202/5/2022Jane Smith
26NCUR2458noyesabcJ6xyzUSCG-Package 3287Vista$ 6,500.00$ 8,000.001/6/20229/4/20202/6/2022Jane Smith
27LKJ2147noyesUSAFJ3CSDUSAF-Package 776534Win XP$ 2,100.00$ 3,500.007/25/20217/5/20212/7/2022Jane Smith
28POI6698yesappleUSAJ4IODUSA-Package 3398Jwin xp$ 9,800.00$ 12,000.009/2/20214/16/20202/8/2022Jane Smith
29ABCS987nonoabcJ1SDDUSAF-Package 776534Windows 7$ 7,400.00$ 8,000.006/6/20213/1/20212/9/2022Joe Doe
30SMN3298noyesUSSFS4CSDUSSF-Package 2312Windows 7$ 6,500.00$ 9,500.009/22/20217/5/20212/10/2022Joe Doe
31LED8852nonodefS4xyzUSSF-Package 2312Windows 10$ 3,500.00$ 3,500.0011/2/20216/7/20202/11/2022John Smith
32LMN326yesappleabcS2CSDUSCG-Package 3287Windows XP$ 2,100.00$ 2,500.007/9/20213/1/20212/12/2022John Doe
33WDC589noUSNS6defUSN-Package 92374BBN Win 7 TTP77$ 1,750.00$ 8,700.002/1/202211/9/20202/13/2022Jane Doe
34VFD365yesyesUSNS6xyzUSN-Package 923Win xp$ 630.00$ 6,500.003/6/20213/25/20202/14/2022Jane Smith
35CVF127yesappleabcS3xyzUSMC-Package 789win 7$ 2,500.00$ 3,500.0012/1/20211/6/20212/15/2022Jane Smith
36CVRF9863yesnoUSNJ2SDDUSN-Package 923windows 7$ 7,800.00$ 7,800.002/2/20229/7/20202/16/2022Jane Smith
37MMLK145nonoabcJ4IODUSMC-Package 789windows 10$ 9,800.00$ 9,800.003/8/20213/19/20212/17/2022John Doe
38EWD441yesyesUSAFS4CSDUSAF-Package 776534windows XP$ 1,200.00$ 4,500.008/5/20217/7/20202/18/2022John Doe
39RRB2285nonodefS5CSDUSAF-Package 776534Windows 7$ 3,200.00$ 4,500.009/5/20219/3/20202/19/2022John Doe
Sheet1
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,223,911
Messages
6,175,334
Members
452,636
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top