ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Repost: hiding columns (https://www.excelbanter.com/excel-programming/294283-repost-hiding-columns.html)

count

Repost: hiding columns
 
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




Tom Ogilvy

Repost: hiding columns
 
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

--
Regards,
Tom Ogilvy

"count" wrote in message
...
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






count

Repost: hiding columns
 
It'll be more elegant now- thanks Tom, very much!

Użytkownik "Tom Ogilvy" napisał w wiadomości
...
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

--
Regards,
Tom Ogilvy

"count" wrote in message
...
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









All times are GMT +1. The time now is 02:08 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com