+ Reply to Thread
Results 1 to 7 of 7

Check two cells within a row and potentially hide the row

  1. #1
    Valued Forum Contributor
    Join Date
    10-10-2012
    Location
    New York
    MS-Off Ver
    Excel 2007/2010
    Posts
    337

    Question Check two cells within a row and potentially hide the row

    I would like to thank you in advance for any help you can provide. I'm new to trying to write code for an excel macro from scratch. I usually record them then tweak.

    I need to build a macro that will check the value of two cells within the same row to make sure they are 0 (zero). If they are both 0 I need the row to be hidden. This needs to be done for a static number of rows.

    Basically: If cell Q41 = 0 AND AC41 = 0 then hide the row. Continue this until row 78, for the given columns, then stop.

    Please let me know if I need to provide more information. Any help is greatly appreciated.

    Regards,

    Craig K.
    Last edited by Craig K.; 10-11-2012 at 03:14 PM.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Check two cells within a row and potentially hide the row

    Sub hidezero
    Dim LR as long, I as long
    LR= cells(rows.count,1).end(xlup).row
    For I = LR to 2 step -1

    If cells(i,1)= cells(i,2) then
    rows(i).hidden= true
    end if
    Next I
    End sub
    Last edited by AB33; 10-10-2012 at 12:22 PM.

  3. #3
    Valued Forum Contributor
    Join Date
    10-10-2012
    Location
    New York
    MS-Off Ver
    Excel 2007/2010
    Posts
    337

    Re: Check two cells within a row and potentially hide the row

    AB33, I'm not quite sure how to adapt that to my needs. When I enter that code into a macro, I get an error at the very beginning.

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Check two cells within a row and potentially hide the row

    Try this one
    Please Login or Register  to view this content.
    Last edited by AB33; 10-10-2012 at 12:28 PM.

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Check two cells within a row and potentially hide the row

    Or specific to your request

    Please Login or Register  to view this content.
    Last edited by AB33; 10-10-2012 at 01:57 PM.

  6. #6
    Valued Forum Contributor
    Join Date
    10-10-2012
    Location
    New York
    MS-Off Ver
    Excel 2007/2010
    Posts
    337

    Re: Check two cells within a row and potentially hide the row

    Thank you very much AB33 . This is exactly what I needed. I have a question for you though.

    I removed the portions of the code where you defined LR, Dim LR As Long and LR = Cells(Rows.Count, 1).End(xlUp).Row and the code works fine. What's the purpose of having those pieces? Should I put them back in?

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Check two cells within a row and potentially hide the row

    Craig,
    Sorry for confusing you and should have explained better. I have removed the unnecessay lines (Please see amended post 6). You do not need to put them back. I is the only varaible we need for your purpose.
    The last code is fixed. It means the code loops from 78 back ward to 41. The first code has flexiblity build on it, so if you wish to adapt it , you can use post 5. It loop through last row to row 2(Back) as long as you have data in Column A, ie that is where LR ends. For e.g, If you have ten rows in column A, your last row would be row 10. You can use any column. In my code I assumed and used column A, but you can change it to suite your needs. For e.g, you could have used one of the choosen columns Q, or AC. I hope this helps.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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