#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 125
Default Hide Columns If...

Hi, I need help with coding to hide columns.
I would like to hide all columns that DON'T have "TM" in the first row. If
I do this, can Row 1 also be hidden?

TIA

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 125
Default Hide Columns If...

I should have added that, at the moment, the cells without "TM" in them are
empty.

"Karin" wrote:

Hi, I need help with coding to hide columns.
I would like to hide all columns that DON'T have "TM" in the first row. If
I do this, can Row 1 also be hidden?

TIA

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,934
Default Hide Columns If...

This macro will that...

Sub HideTMColumns()
Dim C As Range
Dim NonTMcolumns As Range
For Each C In Columns
If Cells(1, C.Column).Value < "TM" Then
If NonTMcolumns Is Nothing Then
Set NonTMcolumns = C
Else
Set NonTMcolumns = Union(C, NonTMcolumns)
End If
End If
Next
NonTMcolumns.EntireColumn.Hidden = True
Rows(1).Hidden = True
End Sub

--
Rick (MVP - Excel)


"Karin" wrote in message
...
Hi, I need help with coding to hide columns.
I would like to hide all columns that DON'T have "TM" in the first row.
If
I do this, can Row 1 also be hidden?

TIA


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Hide Columns If...

At the moment, this macro will hide all columns that are blank in row 1

Will also hide row 1

Sub hide_blank_cols()
Dim c As Range
With ActiveSheet.Rows(1)
Do
Set c = .Find("", LookIn:=xlValues, lookat:=xlWhole, _
MatchCase:=False)
If c Is Nothing Then Exit Do
c.EntireColumn.Hidden = True
Loop
End With
End Sub

For later, assuming your data changes and you will have non-blank cells in
row 1 that don't contain "TM"

Sub hide_cols()
Dim ColNdx As Long
Dim LastCol As Long
LastCol = ActiveSheet.UsedRange.Columns.Count
For ColNdx = LastCol To 1 Step -1
If Cells(ColNdx).Value < "TM" Then
Columns(ColNdx).Hidden = True
End If
Next ColNdx
Rows(1).Hidden = True
End Sub


Gord Dibben MS Excel MVP



On Thu, 4 Sep 2008 14:00:02 -0700, Karin
wrote:

I should have added that, at the moment, the cells without "TM" in them are
empty.

"Karin" wrote:

Hi, I need help with coding to hide columns.
I would like to hide all columns that DON'T have "TM" in the first row. If
I do this, can Row 1 also be hidden?

TIA


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
HIDE COLUMNS HIDE COLUMNS Excel Discussion (Misc queries) 3 July 5th 07 05:56 AM
Hide/Unhide columns using button on top over relevant columns [email protected] Excel Discussion (Misc queries) 1 March 7th 07 09:24 PM
Hide columns cad46230 Excel Discussion (Misc queries) 3 May 13th 06 03:52 PM
Hide columns alm09 Excel Discussion (Misc queries) 1 June 27th 05 04:14 PM
Cannot Hide Columns Joe A Excel Discussion (Misc queries) 2 December 15th 04 10:22 PM


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

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"