+ Reply to Thread
Results 1 to 4 of 4

Hide entire row if a field says NA

  1. #1
    Registered User
    Join Date
    08-04-2006
    Posts
    6

    Hide entire row if a field says NA

    I have multiple pages of a QA Report that are linked into a summary page, which displays the results of input into those multiple pages. On each page, there are questions that need to be answered. What I want to do is, on the summary page, hide the ENTIRE row from those which end up displaying a "NA" answer. Is there some sort of VBA or a macro that would be able to do this? Possibly, after the report is done, click on a button that will activate the code, or simply have it do the hiding on the fly, as answers are entered...

    thanks,

    Perry

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Right click the summary sheet and select view code. Then add this code

    http://www.contextures.com/xlvba01.html#Worksheet

    Change Columns.Count (256) to your Column Number.
    It assumes there is data in Col A. When you select the sheet the code will hide rows with #N/A's and Unhide if no #N/A's


    Please Login or Register  to view this content.
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Registered User
    Join Date
    08-04-2006
    Posts
    6

    can it be automated?

    I did a variation of your code, which worked perfectly (see below). Only have one question: Instead of hooking this code up to a button, can it be executed every time the summary tab is clicked on? (I also tried to add something that would unhide the rows if they didn't say "NA". That worked ok.

    Sub Hide_rows()
    Dim LastRow As Long
    Dim Rng As Range
    Dim Sht As Worksheet
    Dim allwShts As Sheets
    Set allwShts = Worksheets
    Dim Asht As Worksheet
    Set Asht = ActiveSheet
    Application.ScreenUpdating = False
    Range("B35").Select
    ActiveWindow.SmallScroll Down:=72
    Rows("22:103").Select
    Range("B103").Activate
    Selection.EntireRow.Hidden = False
    ActiveWindow.SmallScroll Down:=-81
    Range("C30").Select
    For Each Sht In allwShts
    For i = 1 To allwShts.Count
    Sheets(i).Select
    LastRow = Sheets(i).Range("C65536").End(xlUp).Row ' << Change Col A to your Col
    Set Rng = Sheets(i).Range("C1:C" & LastRow) ' << Change Col A to your col
    For Each cell In Rng
    If cell.Value = "NA" Then
    cell.EntireRow.Hidden = True
    End If
    Next cell
    Next i
    Next Sht
    Asht.Select
    Application.ScreenUpdating = True
    End Sub


    Thanks,

    Perry

  4. #4
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Please read forum rules below and then wrap your code

    VBA Noob

+ 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