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
 

Rmarvin

Board Regular
Joined
May 2, 2012
Messages
77
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:

lefty38

Board Regular
Joined
Oct 27, 2005
Messages
85
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>
 

Rmarvin

Board Regular
Joined
May 2, 2012
Messages
77
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
 

Forum statistics

Threads
1,082,297
Messages
5,364,370
Members
400,792
Latest member
Dxmiian

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top