+ Reply to Thread
Results 1 to 6 of 6

Stop advanced filter when there is no criteria match

  1. #1
    Registered User
    Join Date
    01-04-2013
    Location
    London,England
    MS-Off Ver
    Excel 2007
    Posts
    3

    Stop advanced filter when there is no criteria match

    Hi can someone kindly assist.

    My Objectives are:

    a) Advance filter on worksheet called B.Derivative Exposure using a criteria I have on another worksheet
    b) If the criteria is met then filter all the data under headings which are in row B1:E1 on the worksheet called "Bloomberg - Derivative"
    c) And then for every filtered row in "Bloomberg - Derivative", starting from cell F2, populate formulas from F2 to K2 down to the last filtered row, using column A to infer the last row
    d) And if the criteria is not met, then only expect the formula code to populate the formula columns, in row 2 under the headings, from cells F2 to K2 ONLY.


    Problem:

    When I run the macro, if the criteria is not met I get no data - as you would expect - under the headings in B1 to E1, but the formula code overrides the headings from cell F1 to K1 with the formulas and does so from F2 to K2 as well.

    I've been racking my brains all day to see how I can stop excel from doing this to my headings when the criteria is not met.

    Solution:

    The solution would be to tell excel that if the criteria is not met to go no further and not to populate the formulas in cell f2 to k2 until the last row. The problem is I am not that sophisticated to write that code. Would someone be kind enough to assist?

    Here's the code that I currently have:


    Please Login or Register  to view this content.


    Many thanks,

    Jay

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Stop advanced filter when there is no criteria match

    Why not check if there are any results?

    If there are insert the formulas, if there aren't don't.

    To check could be as simple as seeing if there's a value in row 2 on the results sheet after the filter.

    You might just need to check what X is in your code.

    If it's 1 don't put the formulas in.
    If posting code please use code tags, see here.

  3. #3
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,791

    Re: Stop advanced filter when there is no criteria match

    Can't you use the value of X after applying your advanced filter to determine whether to apply your formulae? Something like this:

    Please Login or Register  to view this content.
    Hope this helps.

    Pete

  4. #4
    Registered User
    Join Date
    01-04-2013
    Location
    London,England
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Stop advanced filter when there is no criteria match

    Nori/ Pete .......... thanks a mil.

    Pete I used your code - replacing the 2 with a 1 - and it works a treat.

    Cheers guys.

    P.S If any of you guys know how to speed that code up, let me know.... I'm not familiar with variables but I am sure that the formula codes can be read once to memory and the results sent in one go...

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Stop advanced filter when there is no criteria match

    As far as I can see you are already sending the formulas in one go.

  6. #6
    Registered User
    Join Date
    01-04-2013
    Location
    London,England
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Stop advanced filter when there is no criteria match

    Thanks Nori

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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