Re: How to write "If column-- is missing" in a for
I don't know of any built-in functions that would do this. However you can write a UDF (User-Defined Function) in VBA that would work. Here's an example.
Please note: even though this is
Volatile, you need to hit your
F9 key to force a ReCalc after you hide/unhide columns/rows.<font face=Courier New><SPAN style="color:#00007F">Function</SPAN> IsHidden(ParamArray rngInput()<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">Variant</SPAN>)<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">Boolean</SPAN><SPAN style="color:#007F00">' UDF to return whether a range is hidden</SPAN>
<SPAN style="color:#00007F">Dim</SPAN> rngCells<SPAN style="color:#00007F">As</SPAN> Range, rngCell<SPAN style="color:#00007F">As</SPAN> Range
IsHidden =<SPAN style="color:#00007F">True</SPAN>
<SPAN style="color:#00007F">On</SPAN><SPAN style="color:#00007F">Error</SPAN><SPAN style="color:#00007F">GoTo</SPAN> BadArgument
Application.Volatile
<SPAN style="color:#00007F">For</SPAN> i =<SPAN style="color:#00007F">LBound</SPAN>(rngInput)<SPAN style="color:#00007F">To</SPAN><SPAN style="color:#00007F">UBound</SPAN>(rngInput)
<SPAN style="color:#00007F">If</SPAN> TypeName(rngInput(i)) = "Range"<SPAN style="color:#00007F">Then</SPAN>
<SPAN style="color:#00007F">Set</SPAN> rngCells = rngInput(i)
<SPAN style="color:#00007F">ElseIf</SPAN> TypeName(rngInput(i)) = "String"<SPAN style="color:#00007F">Then</SPAN>
<SPAN style="color:#00007F">Set</SPAN> rngCells = Range(rngInput(i))
<SPAN style="color:#00007F">Else</SPAN>
<SPAN style="color:#00007F">Set</SPAN> rngCells =<SPAN style="color:#00007F">Nothing</SPAN>
<SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN>
<SPAN style="color:#00007F">If</SPAN><SPAN style="color:#00007F">Not</SPAN> rngCells<SPAN style="color:#00007F">Is</SPAN><SPAN style="color:#00007F">Nothing</SPAN><SPAN style="color:#00007F">Then</SPAN>
<SPAN style="color:#00007F">For</SPAN><SPAN style="color:#00007F">Each</SPAN> rngCell<SPAN style="color:#00007F">In</SPAN> rngCells.Cells
<SPAN style="color:#00007F">If</SPAN><SPAN style="color:#00007F">Not</SPAN> rngCell.EntireColumn.Hidden _
And<SPAN style="color:#00007F">Not</SPAN> rngCell.EntireRow.Hidden<SPAN style="color:#00007F">Then</SPAN> IsHidden =<SPAN style="color:#00007F">False</SPAN>
<SPAN style="color:#00007F">Next</SPAN> rngCell
<SPAN style="color:#00007F">Else</SPAN>
IsHidden =<SPAN style="color:#00007F">False</SPAN>
<SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN>
<SPAN style="color:#00007F">Next</SPAN> i
<SPAN style="color:#00007F">Exit</SPAN><SPAN style="color:#00007F">Function</SPAN>
BadArgument:
<SPAN style="color:#00007F">Set</SPAN> rngCells =<SPAN style="color:#00007F">Nothing</SPAN>
<SPAN style="color:#00007F">Resume</SPAN><SPAN style="color:#00007F">Next</SPAN><SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">Function</SPAN></FONT>
Example of applying this UDF (Note: in my worksheet, column C was hidden, but the HTML-maker utility is showing it.)
HTH