Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Macro to hide column based on header name

I'm looking for a macro that checks the title of columns and hides
particular ones. For example, using the bwlo sample sheet, a macro
that would hide the Age and Location columns automatically:

Name Age Sex Location
John 1 M Home
Steve 4 F Work

As a further capability, I was thinking of creating a spreadsheet with
a listing of all of the columns that I would like hidden, and then
reference that in the macro. So, if the header equals a value on the
column hiding list, the macro would hide that column in my actual
spreadsheet.

Any thoughts? Thanks!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Macro to hide column based on header name

Try something like this:

Sub HideCols()

Dim arr
Dim i As Long
Dim n As Long

'setting up array holding column names to hide
With Sheets("Sheet2")
arr = .Range(.Cells(1), .Cells(10, 1))
End With

For i = 20 To 2 step - 1
For n = 1 To UBound(arr)
If Cells(i) = arr(n, 1) Then
Columns(i).EntireColumn.Hidden = True
Exit For
End If
Next
Next

End Sub

Your list of names to hide will be in Sheet2 in cells A1 to A10 in this
example.


RBS


wrote in message
oups.com...
I'm looking for a macro that checks the title of columns and hides
particular ones. For example, using the bwlo sample sheet, a macro
that would hide the Age and Location columns automatically:

Name Age Sex Location
John 1 M Home
Steve 4 F Work

As a further capability, I was thinking of creating a spreadsheet with
a listing of all of the columns that I would like hidden, and then
reference that in the macro. So, if the header equals a value on the
column hiding list, the macro would hide that column in my actual
spreadsheet.

Any thoughts? Thanks!


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Macro to hide column based on header name

Thanks, sorry for my lameness, but could you show how it would look if
all of column A on sheet 2 contained the values?

Thanks!

RB Smissaert wrote:
Try something like this:

Sub HideCols()

Dim arr
Dim i As Long
Dim n As Long

'setting up array holding column names to hide
With Sheets("Sheet2")
arr = .Range(.Cells(1), .Cells(10, 1))
End With

For i = 20 To 2 step - 1
For n = 1 To UBound(arr)
If Cells(i) = arr(n, 1) Then
Columns(i).EntireColumn.Hidden = True
Exit For
End If
Next
Next

End Sub

Your list of names to hide will be in Sheet2 in cells A1 to A10 in this
example.


RBS


wrote in message
oups.com...
I'm looking for a macro that checks the title of columns and hides
particular ones. For example, using the bwlo sample sheet, a macro
that would hide the Age and Location columns automatically:

Name Age Sex Location
John 1 M Home
Steve 4 F Work

As a further capability, I was thinking of creating a spreadsheet with
a listing of all of the columns that I would like hidden, and then
reference that in the macro. So, if the header equals a value on the
column hiding list, the macro would hide that column in my actual
spreadsheet.

Any thoughts? Thanks!


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Macro to hide column based on header name

Change this:
arr = .Range(.Cells(1), .Cells(10, 1))
to this:
arr = .Range(.Cells(1), .Cells(65536, 1))

RBS

wrote in message
ups.com...
Thanks, sorry for my lameness, but could you show how it would look if
all of column A on sheet 2 contained the values?

Thanks!

RB Smissaert wrote:
Try something like this:

Sub HideCols()

Dim arr
Dim i As Long
Dim n As Long

'setting up array holding column names to hide
With Sheets("Sheet2")
arr = .Range(.Cells(1), .Cells(10, 1))
End With

For i = 20 To 2 step - 1
For n = 1 To UBound(arr)
If Cells(i) = arr(n, 1) Then
Columns(i).EntireColumn.Hidden = True
Exit For
End If
Next
Next

End Sub

Your list of names to hide will be in Sheet2 in cells A1 to A10 in this
example.


RBS


wrote in message
oups.com...
I'm looking for a macro that checks the title of columns and hides
particular ones. For example, using the bwlo sample sheet, a macro
that would hide the Age and Location columns automatically:

Name Age Sex Location
John 1 M Home
Steve 4 F Work

As a further capability, I was thinking of creating a spreadsheet with
a listing of all of the columns that I would like hidden, and then
reference that in the macro. So, if the header equals a value on the
column hiding list, the macro would hide that column in my actual
spreadsheet.

Any thoughts? Thanks!





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 177
Default Macro to hide column based on header name

Hi,
How would you make this work to hide columns that just contain certain
pieces of text. For example, hide all columns that contain the phrase
"apple" so column with header "blue apple" would be hidden? thanks very
much...


"RB Smissaert" wrote:

Change this:
arr = .Range(.Cells(1), .Cells(10, 1))
to this:
arr = .Range(.Cells(1), .Cells(65536, 1))

RBS

wrote in message
ups.com...
Thanks, sorry for my lameness, but could you show how it would look if
all of column A on sheet 2 contained the values?

Thanks!

RB Smissaert wrote:
Try something like this:

Sub HideCols()

Dim arr
Dim i As Long
Dim n As Long

'setting up array holding column names to hide
With Sheets("Sheet2")
arr = .Range(.Cells(1), .Cells(10, 1))
End With

For i = 20 To 2 step - 1
For n = 1 To UBound(arr)
If Cells(i) = arr(n, 1) Then
Columns(i).EntireColumn.Hidden = True
Exit For
End If
Next
Next

End Sub

Your list of names to hide will be in Sheet2 in cells A1 to A10 in this
example.


RBS


wrote in message
oups.com...
I'm looking for a macro that checks the title of columns and hides
particular ones. For example, using the bwlo sample sheet, a macro
that would hide the Age and Location columns automatically:

Name Age Sex Location
John 1 M Home
Steve 4 F Work

As a further capability, I was thinking of creating a spreadsheet with
a listing of all of the columns that I would like hidden, and then
reference that in the macro. So, if the header equals a value on the
column hiding list, the macro would hide that column in my actual
spreadsheet.

Any thoughts? Thanks!




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 177
Default Macro to hide column based on header name

Hi,
How would you make this work to hide columns that just contain certain
pieces of text. For example, hide all columns that contain the phrase
"apple" so column with header "blue apple" would be hidden? thanks very
much...


"RB Smissaert" wrote:

Change this:
arr = .Range(.Cells(1), .Cells(10, 1))
to this:
arr = .Range(.Cells(1), .Cells(65536, 1))

RBS

wrote in message
ups.com...
Thanks, sorry for my lameness, but could you show how it would look if
all of column A on sheet 2 contained the values?

Thanks!

RB Smissaert wrote:
Try something like this:

Sub HideCols()

Dim arr
Dim i As Long
Dim n As Long

'setting up array holding column names to hide
With Sheets("Sheet2")
arr = .Range(.Cells(1), .Cells(10, 1))
End With

For i = 20 To 2 step - 1
For n = 1 To UBound(arr)
If Cells(i) = arr(n, 1) Then
Columns(i).EntireColumn.Hidden = True
Exit For
End If
Next
Next

End Sub

Your list of names to hide will be in Sheet2 in cells A1 to A10 in this
example.


RBS


wrote in message
oups.com...
I'm looking for a macro that checks the title of columns and hides
particular ones. For example, using the bwlo sample sheet, a macro
that would hide the Age and Location columns automatically:

Name Age Sex Location
John 1 M Home
Steve 4 F Work

As a further capability, I was thinking of creating a spreadsheet with
a listing of all of the columns that I would like hidden, and then
reference that in the macro. So, if the header equals a value on the
column hiding list, the macro would hide that column in my actual
spreadsheet.

Any thoughts? Thanks!




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
Macro to Hide rows based on value of column F Scott Marcus Excel Discussion (Misc queries) 10 October 27th 06 11:57 PM
Macro to rearrange/add columns based on column header? drdavidge[_2_] Excel Programming 2 July 8th 06 02:27 AM
Hide column depending on its header Nashlow Excel Programming 2 February 25th 06 02:06 PM
hide columns based on header macro Todd L. Excel Programming 4 December 7th 04 05:53 PM
macro to hide column based on header Todd[_6_] Excel Programming 6 September 4th 03 04:34 AM


All times are GMT +1. The time now is 10:34 PM.

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

About Us

"It's about Microsoft Excel"