+ Reply to Thread
Results 1 to 5 of 5

Hide rows based on Multiple criteria

Hybrid View

berty2000 Hide rows based on Multiple... 05-15-2020, 05:41 AM
AliGW Re: Hide rows based on... 05-15-2020, 06:13 AM
berty2000 Re: Hide rows based on... 05-15-2020, 06:32 AM
Marc L Re: Hide rows based on... 05-15-2020, 09:39 AM
malcmail Re: Hide rows based on... 05-15-2020, 09:45 AM
  1. #1
    Registered User
    Join Date
    03-30-2011
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    15

    Hide rows based on Multiple criteria

    Hi guys

    Im trying to hide rows that have the numbers 1 or 2 in column A
    I can get it to work for one number but cant seem to get it to see the number 2 as well.
    This is what i got so far.

     Dim c As Range
        For Each c In Range("A2:A200").Cells
            If c.Value = "1" And "2" Then
                c.EntireRow.Hidden = True
            End If
        Next c
    Last edited by berty2000; 05-15-2020 at 06:27 AM. Reason: missed code tags off

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2509 (Windows 11 Home 24H2 64-bit)
    Posts
    92,745

    Re: Hide rows based on Multiple criteria

    Administrative Note:

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    03-30-2011
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    15

    Re: Hide rows based on Multiple criteria

    Added the code tags

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Hide rows based on Multiple criteria


    Hi,

    your codeline just not respects the Logic and the coding logic …
    But as a loop is not the best way to go, why don't you use an easy filter or advanced filter ?!

  5. #5
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    331

    Re: Hide rows based on Multiple criteria

    If this is the way you are goin I think the following will work - note the change in the IF statement

    Dim c As Range
        For Each c In Range("A2:A200").Cells
            If c.Value = "1" or c.value="2" Then
                c.EntireRow.Hidden = True
            End If
        Next c
    I don't think AND would have worked in that situation.

+ 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] Hide Rows based on drop down criteria
    By storkhiw in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-02-2017, 11:48 AM
  2. Hide sheets and rows based on multiple criteria
    By toci in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-13-2016, 03:55 PM
  3. [SOLVED] VBa to hide rows based on multiple criteria
    By Sintek in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-22-2016, 10:07 AM
  4. Hide Rows Based on Cell Criteria
    By agroeneveld in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-19-2016, 12:02 PM
  5. VBA to hide rows based on different cells with different criteria
    By Natstin in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-30-2016, 07:07 AM
  6. [SOLVED] Macro to hide rows (Auto filter) based on multiple criteria
    By pauldaddyadams in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-03-2014, 07:36 AM
  7. Excel Macro/ VBA that can hide rows based on multiple criteria
    By hody in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-10-2012, 09:04 AM

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