Hiding columns with 2 conditions / 2 row values

lefty38

Board Regular
Joined
Oct 27, 2005
Messages
85
I have a script i use to hide columns if the returning calculation= 'NR'

and another similar script with I created if another cell = "0" to hide that column

but the two cant run together- each script un-hides the previous script.
(no matter what order they run in)

Question: How do I join (or run concurrently) these two statements together so - each column remains hidden

(Just a note - the two conditions would never be in the same column)

--------------------------------------------------------------------------------
Sub Hide_NR()
Dim rng As Range, cell As Range

Set rng = Range("I5:EZ5")

Application.Calculation = xlAutomatic

For Each cell In rng
Select Case cell.Value
Case Is = "NR"
cell.EntireColumn.Hidden = True
Case Else
cell.EntireColumn.Hidden = False
End Select
Next cell

Application.Calculation = xmanual

End Sub
-----------------------------------------------------------------
Sub Hide_PlaceHolder()
Dim rng As Range, cell As Range

Set rng = Range("I9:EZ9")

Application.Calculation = xlAutomatic

For Each cell In rng
Select Case cell.Value
Case Is = "0"
cell.EntireColumn.Hidden = True
Case Else
cell.EntireColumn.Hidden = False
End Select
Next cell

Application.Calculation = xmanual

End Sub
--------------------------------------------------------------------------------------

thank you
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Try:
Code:
Sub Hide_NR_And_Place_Holder()
Dim rng As Range, cell As Range

Set rng = Range("I5:EZ5", "I9:EZ9")
Application.Calculation = xlAutomatic

For Each cell In rng
Select Case cell.Value
Case Is = "NR"
cell.EntireColumn.Hidden = True
Case Is = "0"
cell.EntireColumn.Hidden = True
Case Is = ""
GoTo NextCell
Case Else
cell.EntireColumn.Hidden = False
End Select
NextCell:
Next cell

Application.Calculation = xmanual

End Sub
Edit: Fixed hiding Black Cells.
 
Last edited:
Upvote 0
the script does work - up to a point
the script finds and hides the "NR" values and hides them
then finds the "0" values and hides them
then looks for blanks (not sure on this piece of it - )
then near then ?end? of the script - the "NR" values re-appear


i will try to include a sample:
[TABLE="width: 1183"]
<TBODY>[TR]
[TD] [/TD]
[TD] [/TD]
[TD="colspan: 2"] [/TD]
[TD]blah</SPAN>[/TD]
[TD]blah</SPAN>[/TD]
[TD]blah</SPAN>[/TD]
[TD]blah</SPAN>[/TD]
[TD]blah</SPAN>[/TD]
[TD]blah</SPAN>[/TD]
[TD]blah</SPAN>[/TD]
[TD]blah</SPAN>[/TD]
[TD]0</SPAN>[/TD]
[TD]0</SPAN>[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD="colspan: 2"] [/TD]
[TD]blah</SPAN>[/TD]
[TD]blah</SPAN>[/TD]
[TD]blah</SPAN>[/TD]
[TD]blah</SPAN>[/TD]
[TD]blah</SPAN>[/TD]
[TD]blah</SPAN>[/TD]
[TD]blah</SPAN>[/TD]
[TD]blah</SPAN>[/TD]
[TD="align: right"]0</SPAN>[/TD]
[TD="align: right"]0</SPAN>[/TD]
[/TR]
[TR]
[TD="colspan: 2"] [/TD]
[TD="colspan: 2"]Requierd</SPAN>[/TD]
[TD]2</SPAN>[/TD]
[TD]2</SPAN>[/TD]
[TD]2</SPAN>[/TD]
[TD]2</SPAN>[/TD]
[TD]2</SPAN>[/TD]
[TD]2</SPAN>[/TD]
[TD]2</SPAN>[/TD]
[TD]0</SPAN>[/TD]
[TD]0</SPAN>[/TD]
[TD]0</SPAN>[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD="colspan: 2"]Completions</SPAN>[/TD]
[TD]2</SPAN>[/TD]
[TD]0</SPAN>[/TD]
[TD]0</SPAN>[/TD]
[TD]2</SPAN>[/TD]
[TD]0</SPAN>[/TD]
[TD]0</SPAN>[/TD]
[TD]0</SPAN>[/TD]
[TD]0</SPAN>[/TD]
[TD]0</SPAN>[/TD]
[TD]0</SPAN>[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD="colspan: 2"]% Complete</SPAN>[/TD]
[TD]100.0%[/TD]
[TD]0.0%</SPAN>[/TD]
[TD]0.0%</SPAN>[/TD]
[TD]100.0%[/TD]
[TD]0.0%</SPAN>[/TD]
[TD]0.0%</SPAN>[/TD]
[TD]0.0%</SPAN>[/TD]
[TD]NR[/TD]
[TD]NR[/TD]
[TD]NR[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD="colspan: 2"] [/TD]
[TD]xx[/TD]
[TD]xx[/TD]
[TD]xx[/TD]
[TD]xx[/TD]
[TD]xx[/TD]
[TD]xx[/TD]
[TD]xx[/TD]
[TD]1/0/00</SPAN>[/TD]
[TD]1/0/00</SPAN>[/TD]
[TD]1/0/00</SPAN>[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD]item</SPAN>[/TD]
[TD]item</SPAN>[/TD]
[TD]item</SPAN>[/TD]
[TD]item</SPAN>[/TD]
[TD]item</SPAN>[/TD]
[TD]item</SPAN>[/TD]
[TD]item</SPAN>[/TD]
[TD]0</SPAN>[/TD]
[TD]0</SPAN>[/TD]
[TD]0</SPAN>[/TD]
[/TR]
[TR]
[TD]Employee</SPAN>[/TD]
[TD] ID</SPAN>[/TD]
[TD]type[/TD]
[TD]Shift</SPAN>[/TD]
[TD]item</SPAN>[/TD]
[TD]item</SPAN>[/TD]
[TD]item</SPAN>[/TD]
[TD]item</SPAN>[/TD]
[TD]item</SPAN>[/TD]
[TD]item</SPAN>[/TD]
[TD]item</SPAN>[/TD]
[TD]item</SPAN>[/TD]
[TD]item</SPAN>[/TD]
[TD]item</SPAN>[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]item</SPAN>[/TD]
[TD]item</SPAN>[/TD]
[TD]item</SPAN>[/TD]
[TD]item</SPAN>[/TD]
[TD]item</SPAN>[/TD]
[TD]item</SPAN>[/TD]
[TD]item</SPAN>[/TD]
[TD]xx2[/TD]
[TD="align: right"]0</SPAN>[/TD]
[TD="align: right"]0</SPAN>[/TD]
[/TR]
[TR]
[TD]MAURICE</SPAN>[/TD]
[TD="align: right"]222[/TD]
[TD]</SPAN>[/TD]
[TD]1</SPAN>[/TD]
[TD]05-13</SPAN>[/TD]
[TD]NR</SPAN>[/TD]
[TD]NR</SPAN>[/TD]
[TD]05-29</SPAN>[/TD]
[TD]NR</SPAN>[/TD]
[TD]NR</SPAN>[/TD]
[TD]NR</SPAN>[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]NATHANIEL</SPAN>[/TD]
[TD="align: right"]123[/TD]
[TD]</SPAN>[/TD]
[TD]2</SPAN>[/TD]
[TD]05-07</SPAN>[/TD]
[TD]NR</SPAN>[/TD]
[TD]NR</SPAN>[/TD]
[TD]05-02</SPAN>[/TD]
[TD]NR</SPAN>[/TD]
[TD]NR</SPAN>[/TD]
[TD]NR</SPAN>[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</TBODY><COLGROUP><COL><COL span=3><COL span=10></COLGROUP>[/TABLE]
 
Upvote 0
Try removing the "Case else" :
Code:
Sub Hide_NR_And_Place_Holder()
Dim rng As Range, cell As Range

Set rng = Range("I5:EZ5", "I9:EZ9")
Application.Calculation = xlAutomatic

For Each cell In rng
Select Case cell.Value
Case Is = "NR"
cell.EntireColumn.Hidden = True
Case Is = "0"
cell.EntireColumn.Hidden = True
Case Is = ""
GoTo NextCell
End Select
NextCell:
Next cell

Application.Calculation = xmanual

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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