1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

FilterByColour - Code Improvement Suggestions

Discussion in 'Business Applications' started by MRdNk, Mar 25, 2008.

Thread Status:
Not open for further replies.
Advertisement
  1. MRdNk

    MRdNk Thread Starter

    Joined:
    Apr 7, 2007
    Messages:
    439
    Hi All,

    I've written a Macro, to Filter by Colour, however I'm sure there's a better way of doing it, please advise.
    And the Unhide Sub
    Ps. Also includes a records count.

    Tried to For Each Cell In ??? (got stuck here).
     
  2. bomb #21

    bomb #21

    Joined:
    Jul 1, 2005
    Messages:
    8,546
    "a better way of doing it, please advise." & "Tried to For Each Cell In ??? (got stuck here)."

    Certainly you should avoid physical selection of sheets/ranges/cells wherever possible, in terms of efficiency.

    For the For/Next construct, something like:

    For Each Cell In Range("A1", Range("A" & Rows.Count).End(xlUp))
    MsgBox Cell.Address' (i.e. your code to loop here)
    Next Cell


    HTH
     
  3. MRdNk

    MRdNk Thread Starter

    Joined:
    Apr 7, 2007
    Messages:
    439
    That's great thank you.

    I've used a named range with OFFSET and COUNTA for the height to improve it further.
    Excellent.

    My description, of what I was looking for was a bit lame, long day.
     
  4. bomb #21

    bomb #21

    Joined:
    Jul 1, 2005
    Messages:
    8,546
    Something I regularly forget to remember ( :D ) is ... how many records are we talking?

    Code execution can often be greatly sped up by wrapping the "bulk" between:

    Application.ScreenUpdating=False

    and

    Application.ScreenUpdating=True

    :cool:
     
  5. jimr381

    jimr381

    Joined:
    Jul 20, 2007
    Messages:
    4,189
    First Name:
    Jim
    I want to say it is built into 2007 as well. At least I know you can sort by color if I recall, but do not remember if you can filter.
     
  6. MRdNk

    MRdNk Thread Starter

    Joined:
    Apr 7, 2007
    Messages:
    439
    Yeah, I'm pretty sure 2007 does have Filter by Colour which is a great addition. Unfortunately I'm still on 2003 as is the place I work - and I'm sure it'll be a while before its standard.
     
  7. MRdNk

    MRdNk Thread Starter

    Joined:
    Apr 7, 2007
    Messages:
    439
    How would I do it, if the colour was determined by a conditional format?
     
  8. bomb #21

    bomb #21

    Joined:
    Jul 1, 2005
    Messages:
    8,546
    AFAIK code can't see colours "created" by conditional formatting, therefore you can't. You'd have to have the code check for the same conditions that governed the CF.
     
  9. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/697074

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice