Repost: hiding columns

C

count

Hi, with special bow to Bob and Frank :)
I re-clarify my previous post:

Task at hand is to hide a dozen columns i a "Main" sheet. - it has many more
of them.
I listed headings of interesting columns, stored them in 1 column vertical
list and named it "Elements" (stored on separate sheet)
I need effcient metod of parsing header row of the sheet and change column
width to 0 of those that match "Elements"
I think I saw a 1-liner or so for the task. I used to do full 2 range
looping - but it's 21st century, so I figure I gotta move ahead... :)

TIA
Paul
 
T

Tom Ogilvy

there is no clever means to match a name in one column to the header in
another sheet.


You can use match to eliminate one loop

Dim rng as Range, cell as Range
Dim res as Variant
With Worksheets("Main")
set rng = .Range(cells(1,1),Cells(1,256).End(xltoLeft))
End With
for each cell in Range("Elements")
res = application.Match(cell,rng,0)
if not iserror(res) then
rng(1,res).EntireColumn.Hidden=True
end if
Next
 
Top