Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Select a column based on a cell entry

I've been struggling for a day now in trying to write a macro that will
cycle through all the worksheets in a workbook, then check each column
for the word "HIDE" in a certain row (15) in each column, then if it
finds it, hides the column.

e.g.(with a bit of psudo code thrown in :-(

For I = 1 To Worksheets.Count
ActiveWorkbook.Worksheets(I).Select

For Each col In Worksheets(I).Columns

if row 15 = "HIDE"
Then
Column(col).Select
Selection.EntireColumn.Hidden = True
Next col

Next


I've tried most things, but my VBA skills are not yet good enough to
manage this.

Any help anybody?? Please??

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Select a column based on a cell entry

You were very, very close to having it!

Public Sub HideColumns()
Dim I as Integer, col As Range

For I = 1 To ThisWorkbook.Worksheets.Count
For Each col In Worksheets(I).Columns
If col.Cells(15, 1) = "HIDE" Then col.Hidden = True
Next col
Next I

End Sub

NOTE: in code you do not need to Select a book, sheet, or range in order to
use it, as long as you provide the proper object references
--
- K Dales


" wrote:

I've been struggling for a day now in trying to write a macro that will
cycle through all the worksheets in a workbook, then check each column
for the word "HIDE" in a certain row (15) in each column, then if it
finds it, hides the column.

e.g.(with a bit of psudo code thrown in :-(

For I = 1 To Worksheets.Count
ActiveWorkbook.Worksheets(I).Select

For Each col In Worksheets(I).Columns

if row 15 = "HIDE"
Then
Column(col).Select
Selection.EntireColumn.Hidden = True
Next col

Next


I've tried most things, but my VBA skills are not yet good enough to
manage this.

Any help anybody?? Please??


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Select a column based on a cell entry

Many thanks
Works a treat -
Ah - "very, very close to having it", you are too kind.
Unfortunately not close enough for Excel :-(
It's a bit like "sort of" -
"This is your pilot speaking, we will be landing in London in 30 minutes -
sort of" :-)

Many thanks again -
Regards Alan F.


"K Dales" wrote in message
...
You were very, very close to having it!

Public Sub HideColumns()
Dim I as Integer, col As Range

For I = 1 To ThisWorkbook.Worksheets.Count
For Each col In Worksheets(I).Columns
If col.Cells(15, 1) = "HIDE" Then col.Hidden = True
Next col
Next I

End Sub

NOTE: in code you do not need to Select a book, sheet, or range in order
to
use it, as long as you provide the proper object references
--
- K Dales


" wrote:

I've been struggling for a day now in trying to write a macro that will
cycle through all the worksheets in a workbook, then check each column
for the word "HIDE" in a certain row (15) in each column, then if it
finds it, hides the column.

e.g.(with a bit of psudo code thrown in :-(

For I = 1 To Worksheets.Count
ActiveWorkbook.Worksheets(I).Select

For Each col In Worksheets(I).Columns

if row 15 = "HIDE"
Then
Column(col).Select
Selection.EntireColumn.Hidden = True
Next col

Next


I've tried most things, but my VBA skills are not yet good enough to
manage this.

Any help anybody?? Please??




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automtacally change entry based on value in column. Richhall[_2_] Excel Worksheet Functions 1 June 18th 09 08:45 PM
Automating to autofill column B based on column A entry GirlFridayCA Excel Discussion (Misc queries) 2 December 2nd 08 10:46 PM
restricting entry into a cell based on entry to a previous cell newbie57 New Users to Excel 1 June 9th 08 05:43 PM
Auto entry of data based on entry of text in another column or fie Judy Rose Excel Discussion (Misc queries) 2 May 21st 08 01:14 PM
Help tonight?!! select rows based on cell value in a column Lighthouse1 Excel Worksheet Functions 1 January 31st 07 02:57 AM


All times are GMT +1. The time now is 09:38 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"