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

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)
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:
blah</SPAN>blah</SPAN>blah</SPAN>blah</SPAN>blah</SPAN>blah</SPAN>blah</SPAN>blah</SPAN>0</SPAN>0</SPAN>
blah</SPAN>blah</SPAN>blah</SPAN>blah</SPAN>blah</SPAN>blah</SPAN>blah</SPAN>blah</SPAN>0</SPAN>0</SPAN>
Requierd</SPAN>2</SPAN>2</SPAN>2</SPAN>2</SPAN>2</SPAN>2</SPAN>2</SPAN>0</SPAN>0</SPAN>0</SPAN>
Completions</SPAN>2</SPAN>0</SPAN>0</SPAN>2</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>
% Complete</SPAN>100.0%0.0%</SPAN>0.0%</SPAN>100.0%0.0%</SPAN>0.0%</SPAN>0.0%</SPAN>NRNRNR
xxxxxxxxxxxxxx1/0/00</SPAN>1/0/00</SPAN>1/0/00</SPAN>
item</SPAN>item</SPAN>item</SPAN>item</SPAN>item</SPAN>item</SPAN>item</SPAN>0</SPAN>0</SPAN>0</SPAN>
Employee</SPAN> ID</SPAN>typeShift</SPAN>item</SPAN>item</SPAN>item</SPAN>item</SPAN>item</SPAN>item</SPAN>item</SPAN>item</SPAN>item</SPAN>item</SPAN>
item</SPAN>item</SPAN>item</SPAN>item</SPAN>item</SPAN>item</SPAN>item</SPAN>xx20</SPAN>0</SPAN>
MAURICE</SPAN>222</SPAN>1</SPAN>05-13</SPAN>NR</SPAN>NR</SPAN>05-29</SPAN>NR</SPAN>NR</SPAN>NR</SPAN>
NATHANIEL</SPAN>123</SPAN>2</SPAN>05-07</SPAN>NR</SPAN>NR</SPAN>05-02</SPAN>NR</SPAN>NR</SPAN>NR</SPAN>

<TBODY>
</TBODY><COLGROUP><COL><COL span=3><COL span=10></COLGROUP>
 
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,214,527
Messages
6,120,057
Members
448,940
Latest member
mdusw

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