VBA to Auto Hide Rows with N/A as Value

Bkisley

Board Regular
Joined
Jan 5, 2017
Messages
100
Hey guys! I have a macro created that is near perfect for what I need. The only downfall is that it leaves the 50 rows the macro deals with unhidden. I need to add to my macro to hide all rows with rows 56 and 105 that have a value of N/A in column A.

Example - cells A56:A66 all have a percent in the cell. Cells A67:A105 have N/A in the cell. When I click my macro button, I need to automatically hide rows A67:105. If I then add to my data and now A56:A75 now have a percent in the cell, I would need my macro (when clicked for the second time) to leave rows A56:A75 unhidden and hide A76:A105

What do I need to do??


Thanks!
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
How about
Code:
Sub HideNA()
   Range("A56:A105").SpecialCells(xlFormulas, xlErrors).EntireRow.Hidden = True
End Sub
 
Upvote 0
I guess I should have explained this better, the formula I have does not return an error N/A but rather me literally typing N/A. I have an if statement and when it is false, the end of my equation looks like --> ,"N/A")
 
Upvote 0
Ok, what code do you already have?
 
Upvote 0
@Fluff
Code:
Sub OnePercentDown()
'
' OnePercentDown Macro
'


'
    Sheets("Financial Model").Select
    Range("F56:F105").Select
    Selection.Cut
    ActiveWindow.SmallScroll ToRight:=3
    Range("Y56").Select
    ActiveSheet.Paste
    Range("F56").Select
    ActiveCell.FormulaR1C1 = "=RC[19]*(1-1%)"
    Range("F56").Select
    Selection.AutoFill Destination:=Range("F56:F105"), Type:=xlFillDefault
    Range("F56:F105").Select
    Selection.NumberFormat = "$#,##0.000"
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    Range("Y56:Y105").Select
    Sheets("Financial Summary - System").Select
    Range("E13").Select
    Selection.Copy
    Range("E22").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("E9").Select
    Application.CutCopyMode = False
    Selection.Copy
    Range("E23").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("E15:E16").Select
    Application.CutCopyMode = False
    Selection.Copy
    Range("E24").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Sheets("Financial Model").Select
    Application.CutCopyMode = False
    Selection.Cut
    Range("F56").Select
    ActiveSheet.Paste
    ActiveWindow.ScrollColumn = 3
    ActiveWindow.ScrollColumn = 2
    ActiveWindow.ScrollColumn = 1
[B][COLOR=#ff0000]THIS IS WHERE I NEED THE HIDE COMMAND[/COLOR][/B]
    Sheets("Financial Summary - System").Select
    Range("C25").Select
End Sub
 
Last edited by a moderator:
Upvote 0
First off, when posting code, please use the code tags (the # icon in the reply window).

Secondly try
Code:
    For Each Cl In Range("A56:A105")
      If Cl.Value = "N/A" Then
         Cl.EntireRow.Hidden = True
      Else
         Cl.EntireRow.Hidden = False
      End If
   Next Cl
 
Upvote 0
If you are happy to change your formula so that, rather returning "N/A" it returns FALSE (no quotes) you could use
Code:
Range("A56:A105").SpecialCells(xlFormulas, xlLogical).EntireRow.Hidden = True
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top