+ Reply to Thread
Results 1 to 38 of 38

how to using marcro to check double condition

  1. #1
    Registered User
    Join Date
    10-07-2015
    Location
    Canada
    MS-Off Ver
    2003
    Posts
    25

    how to using marcro to check double condition

    hi,
    i want to make a macro to do below
    while the column "booking Number" in sheet2 = "Booking#" in Sheet1
    then check the POR in sheet1, if POR = "AES" keep the row in sheet2. otherwise delete the whole row in Sheet2
    at botton of sheet2 list of count the total "Container Number" & unique "Booking Number"


    the difficult is in sheet1, customer could combine several bookings into 1 BL. so that there are several booking # listed using ";" we need to check all of single bookings. if 1 of the combined bookings has list a "AES" will also need to be shown in Sheet2, can not be deleted.
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    10-07-2015
    Location
    Canada
    MS-Off Ver
    2003
    Posts
    25

    Re: how to using marcro to check double condition

    i know it is quicker to use Access the only problem is the double booking numbers sometimes i manually create a new table items to move the second booking number over. but this is taking lots of times.

  3. #3
    Registered User
    Join Date
    10-07-2015
    Location
    Canada
    MS-Off Ver
    2003
    Posts
    25

    Re: how to using marcro to check double condition

    i had below code but not able to run, please correct me if anything wrong
    Please Login or Register  to view this content.
    Last edited by alansidman; 10-19-2015 at 06:40 PM. Reason: code tags added

  4. #4
    Registered User
    Join Date
    10-07-2015
    Location
    Canada
    MS-Off Ver
    2003
    Posts
    25

    Re: how to using marcro to check double condition

    someone please help

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,461

    Re: how to using marcro to check double condition

    Do you really need code?

    You could put this formula in cell K2 and copy down:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Then filter on "delete" and select and delete the visible rows.

    Easy enough to put that in a macro.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  6. #6
    Registered User
    Join Date
    10-07-2015
    Location
    Canada
    MS-Off Ver
    2003
    Posts
    25

    Re: how to using marcro to check double condition

    but the point is i want to do this for my co-worker (old guy) who dont know very well of excel.
    i just want him to click a botton then done.

  7. #7
    Registered User
    Join Date
    10-07-2015
    Location
    Canada
    MS-Off Ver
    2003
    Posts
    25

    Re: how to using marcro to check double condition

    Hi TMS, i tested your fomula, however it return delete for the double booking number cell which should keep

  8. #8
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: how to using marcro to check double condition

    Hi frez

    I, too, am an "Old Guy" and like to keep things "simple" for we "Old Guys".

    Tell me, how many Booking Numbers in Column C of Sheet1 can be ganged up with the ";" symbol...any idea...or should I assume "unknown"?
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  9. #9
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,893

    Re: how to using marcro to check double condition

    @frez Code Tags Added
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (Because you are new to the forum, I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  10. #10
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: how to using marcro to check double condition

    Hi Frez,

    Try this:

    Please Login or Register  to view this content.
    Last edited by xladept; 10-19-2015 at 06:55 PM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  11. #11
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: how to using marcro to check double condition

    Hi frez

    This Code is in the attached...click the Button...let me know of issues.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  12. #12
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: how to using marcro to check double condition

    Please Login or Register  to view this content.
    or

    Please Login or Register  to view this content.
    Last edited by snb; 10-20-2015 at 03:29 AM.



  13. #13
    Registered User
    Join Date
    10-07-2015
    Location
    Canada
    MS-Off Ver
    2003
    Posts
    25

    Re: how to using marcro to check double condition

    hi Jaslake,


    the most i saw are around 11 bookings all combined into 1 BLs.

  14. #14
    Registered User
    Join Date
    10-07-2015
    Location
    Canada
    MS-Off Ver
    2003
    Posts
    25

    Re: how to using marcro to check double condition

    thanks Alansidman

  15. #15
    Registered User
    Join Date
    10-07-2015
    Location
    Canada
    MS-Off Ver
    2003
    Posts
    25

    Re: how to using marcro to check double condition

    hi Xladept, according to this code, you use the booking number in Sheet2 to check if it = to BL number in Sheet1, but i dont think that has any relationship in between, we still could use different BL number it is not a must to use the same number for BL and bookings.

  16. #16
    Registered User
    Join Date
    10-07-2015
    Location
    Canada
    MS-Off Ver
    2003
    Posts
    25

    Re: how to using marcro to check double condition

    thanks Jaslake, however, this code runs really slow and it seems like it is not really delete the right sections.

  17. #17
    Registered User
    Join Date
    10-07-2015
    Location
    Canada
    MS-Off Ver
    2003
    Posts
    25

    Re: how to using marcro to check double condition

    hi SNB,

    thanks for your code, however it delete the wrong section, we should keep the "AES" and delete the rest. i think we should overwrite (If sn(j, 2) = "AES") into (If sn(j, 2) <> "AES").

  18. #18
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: how to using marcro to check double condition

    Hi frez

    Ah well, we tried...if you could expand on this a bit (based on the Sample Data)...I might look at it again...if not...so be it.
    it seems like it is not really delete the right sections

  19. #19
    Registered User
    Join Date
    10-07-2015
    Location
    Canada
    MS-Off Ver
    2003
    Posts
    25

    Re: how to using marcro to check double condition

    i am testing on SNB's code right now, if that works well, i dont have to get you rewrite your code, i need to rewrite a bit from that due to my coworker might not use the same column with me. thanks anyway Jaslake.
    Quote Originally Posted by jaslake View Post
    Hi frez

    Ah well, we tried...if you could expand on this a bit (based on the Sample Data)...I might look at it again...if not...so be it.

  20. #20
    Registered User
    Join Date
    10-07-2015
    Location
    Canada
    MS-Off Ver
    2003
    Posts
    25

    Re: how to using marcro to check double condition

    hi SNB, i tested on this code, only 1 problem, looks like it miss the first row if it is double booking number in it.

    Quote Originally Posted by snb View Post

    Please Login or Register  to view this content.

  21. #21
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: how to using marcro to check double condition

    Another attempt:

    Please Login or Register  to view this content.

  22. #22
    Registered User
    Join Date
    10-07-2015
    Location
    Canada
    MS-Off Ver
    2003
    Posts
    25

    Re: how to using marcro to check double condition

    hi xladept, Macro stopped running due to BNum type doesnt match on highlighted lines, i updated the type to string then it didnt delete anything but returned the total of BLs and containers.

    Quote Originally Posted by xladept View Post
    Another attempt:

    Please Login or Register  to view this content.

  23. #23
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: how to using marcro to check double condition

    Have you used a different sheet - do, we need a different sample?

  24. #24
    Registered User
    Join Date
    10-07-2015
    Location
    Canada
    MS-Off Ver
    2003
    Posts
    25

    Re: how to using marcro to check double condition

    here i attached a new one, this is a bit longer than the pervious.
    Attached Files Attached Files

  25. #25
    Registered User
    Join Date
    10-07-2015
    Location
    Canada
    MS-Off Ver
    2003
    Posts
    25

    Re: how to using marcro to check double condition

    or we may use this attachment, i deleted the columns dont need for calculation.
    Attached Files Attached Files
    Last edited by frez; 10-21-2015 at 05:08 PM.

  26. #26
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: how to using marcro to check double condition

    I tried the program on both and it ran handily

  27. #27
    Registered User
    Join Date
    10-07-2015
    Location
    Canada
    MS-Off Ver
    2003
    Posts
    25

    Re: how to using marcro to check double condition

    hi Xladept

    i think there might be some miscommunication, what i want is keep the containers with AES and delete the rest, and get a total of how many containers with AES.

    i tried your code and it doesnt delete any lines, only show the total of booking numbers and total of container type. or do we need to change the column order?

    Quote Originally Posted by xladept View Post
    I tried the program on both and it ran handily

  28. #28
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: how to using marcro to check double condition

    The first one went from 683 lines to 622 lines.

    The second went from 813 lines to 772 lines.


  29. #29
    Registered User
    Join Date
    10-07-2015
    Location
    Canada
    MS-Off Ver
    2003
    Posts
    25

    Re: how to using marcro to check double condition

    on file.xlsx should return 4 BLs, 53 containers and 3 bookings
    on File2 should return 36 BLs, 305 containers and 43 bookings.

    i just re-upload file2 just now. please kindly download it again and try.

  30. #30
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: how to using marcro to check double condition

    Hi Frez,

    at botton of sheet2 list of count the total "Container Number" & unique "Booking Number"
    You have no containers on your latest download but I got 52 bookings

  31. #31
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: how to using marcro to check double condition

    This uses Column A to count Containers and I get 52 Boolings and 405 Containers:

    Please Login or Register  to view this content.
    Do you want the BL's from sheet1 to be counted also??
    Last edited by xladept; 10-21-2015 at 05:38 PM.

  32. #32
    Registered User
    Join Date
    10-07-2015
    Location
    Canada
    MS-Off Ver
    2003
    Posts
    25

    Re: how to using marcro to check double condition

    containers are in sheet2 Column A, the booking number for each container should serch in Sheet1 -Booking#, then we check column B, if it has a AES we keep the line for that container, if not we delete the line in Sheet2.

    Quote Originally Posted by xladept View Post
    Hi Frez,


    You have no containers on your latest download but I got 52 bookings

  33. #33
    Registered User
    Join Date
    10-07-2015
    Location
    Canada
    MS-Off Ver
    2003
    Posts
    25

    Re: how to using marcro to check double condition

    after run your new code, the first 100 containers do not belongs to AES. should delete as well, but the code didnt.
    first container's booking number is 8004676430 in Sheet1 it returned SUM instead of AES

  34. #34
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: how to using marcro to check double condition

    I didn't specify which book - try it now:

    Please Login or Register  to view this content.

  35. #35
    Registered User
    Join Date
    10-07-2015
    Location
    Canada
    MS-Off Ver
    2003
    Posts
    25

    Re: how to using marcro to check double condition

    yes, i run the code for those 2 files are both works fine. let me try several more first then i can solve it

    Quote Originally Posted by xladept View Post
    I didn't specify which book - try it now:

  36. #36
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: how to using marcro to check double condition

    This may be it!

    Please Login or Register  to view this content.

  37. #37
    Registered User
    Join Date
    10-07-2015
    Location
    Canada
    MS-Off Ver
    2003
    Posts
    25

    Re: how to using marcro to check double condition

    thanks a lot Xladept, this works really well. i tested several files already, it all returned the correct counts. thanks.

  38. #38
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: how to using marcro to check double condition

    You're welcome! Whew!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Double match - 1 condition is not exact
    By Gukupozu in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 04-10-2015, 06:06 AM
  2. Double condition Vlookup
    By Zaid in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 01-30-2014, 05:40 AM
  3. [SOLVED] IF formula with double condition
    By dreddster in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-15-2013, 07:43 AM
  4. Double Quotes in text with if condition
    By kishoremcp in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-11-2012, 03:02 AM
  5. [SOLVED] Count double entry as one & with condition
    By [email protected] in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 11-25-2012, 10:31 PM
  6. Excel 2007 : Double IF Condition..Please Help
    By gun3d in forum Excel General
    Replies: 1
    Last Post: 05-20-2011, 05:57 AM
  7. Double lookup condition required
    By heatwave in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-03-2009, 05:38 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1