#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 49
Default Hide a column "if"?

Hello,

I have a workbook with 250 sheets. I need to be able to hide column F unless
cell E2 has the value "Level 1". If there is another value in E2 or it is
blank, I need column F to be hidden. I need this on all 250 sheets. Is this
possible?

Thanks in advance, you are all always to helpful!

tgcali
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default Hide a column "if"?

Hi,

Alt +f11 to open VB editor, right click 'This Workbook' and insert module
and paste this in.

Sub sonic()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Select
If Range("E2").Value < "Level 1" Then
Columns("F:F").EntireColumn.Hidden = True
End If
Next
End Sub

Mike

"tgcali" wrote:

Hello,

I have a workbook with 250 sheets. I need to be able to hide column F unless
cell E2 has the value "Level 1". If there is another value in E2 or it is
blank, I need column F to be hidden. I need this on all 250 sheets. Is this
possible?

Thanks in advance, you are all always to helpful!

tgcali

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default Hide a column "if"?

on reflection try this instead

Sub sonic()
Dim ws As Worksheet
For x = 1 To Worksheets.Count
If Worksheets(x).Range("E2").Value < "Level 1" Then
Worksheets(x).Columns("F:F").EntireColumn.Hidden = True
End If
Next
End Sub

Mike

"tgcali" wrote:

Hello,

I have a workbook with 250 sheets. I need to be able to hide column F unless
cell E2 has the value "Level 1". If there is another value in E2 or it is
blank, I need column F to be hidden. I need this on all 250 sheets. Is this
possible?

Thanks in advance, you are all always to helpful!

tgcali

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 49
Default Hide a column "if"?

Mike,

Thank you for your reply. I can't get it to work. I get a run time error on
the line right above End If.

Where/how am I supposed to right click 'this workbook' after I do altF11?
Maybe that's the trouble?

tgcali

"Mike H" wrote:

Hi,

Alt +f11 to open VB editor, right click 'This Workbook' and insert module
and paste this in.

Sub sonic()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Select
If Range("E2").Value < "Level 1" Then
Columns("F:F").EntireColumn.Hidden = True
End If
Next
End Sub

Mike

"tgcali" wrote:

Hello,

I have a workbook with 250 sheets. I need to be able to hide column F unless
cell E2 has the value "Level 1". If there is another value in E2 or it is
blank, I need column F to be hidden. I need this on all 250 sheets. Is this
possible?

Thanks in advance, you are all always to helpful!

tgcali

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 49
Default Hide a column "if"?

I get the error in the same place for both of them. Any suggestions?

tgcali

"Mike H" wrote:

on reflection try this instead

Sub sonic()
Dim ws As Worksheet
For x = 1 To Worksheets.Count
If Worksheets(x).Range("E2").Value < "Level 1" Then
Worksheets(x).Columns("F:F").EntireColumn.Hidden = True
End If
Next
End Sub

Mike

"tgcali" wrote:

Hello,

I have a workbook with 250 sheets. I need to be able to hide column F unless
cell E2 has the value "Level 1". If there is another value in E2 or it is
blank, I need column F to be hidden. I need this on all 250 sheets. Is this
possible?

Thanks in advance, you are all always to helpful!

tgcali



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default Hide a column "if"?

Hi,

I've tried to replicate the error but can't so lets try again and a bit
simpler maybe.
It will work as worksheet code so right click the sheet tab of any sheet and
in the pop-up menu click 'View code'.

Paste this in on the right hand side and still in VB editor with the cursor
in the sub tap F5

Sub sonic()
For x = 1 To Worksheets.Count
If Worksheets(x).Range("E2").Value < "Level 1" Then
Worksheets(x).Columns("F:F").EntireColumn.Hidden = True
End If
Next
End Sub

Mike

"tgcali" wrote:

I get the error in the same place for both of them. Any suggestions?

tgcali

"Mike H" wrote:

on reflection try this instead

Sub sonic()
Dim ws As Worksheet
For x = 1 To Worksheets.Count
If Worksheets(x).Range("E2").Value < "Level 1" Then
Worksheets(x).Columns("F:F").EntireColumn.Hidden = True
End If
Next
End Sub

Mike

"tgcali" wrote:

Hello,

I have a workbook with 250 sheets. I need to be able to hide column F unless
cell E2 has the value "Level 1". If there is another value in E2 or it is
blank, I need column F to be hidden. I need this on all 250 sheets. Is this
possible?

Thanks in advance, you are all always to helpful!

tgcali

  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Hide a column "if"?

After you press Alt+F11, you are taken into the VBA editor. In the upper
left portion of the editor window is the Project Explorer window (its title
bar starts with the word "Project")... if you don't see it, press Ctrl+R. In
the Project Explorer window is an item labeled "ThisWorkbook"... right-click
it and click on Insert/Module on the popup menu that appeared. A code window
will be displayed in the right-hand pane when you do this... paste the code
you were given in it. You can now call the 'sonic' subroutine from your own
code that you place in the worksheet's code window.

Rick


"tgcali" wrote in message
...
Mike,

Thank you for your reply. I can't get it to work. I get a run time error
on
the line right above End If.

Where/how am I supposed to right click 'this workbook' after I do altF11?
Maybe that's the trouble?

tgcali

"Mike H" wrote:

Hi,

Alt +f11 to open VB editor, right click 'This Workbook' and insert module
and paste this in.

Sub sonic()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Select
If Range("E2").Value < "Level 1" Then
Columns("F:F").EntireColumn.Hidden = True
End If
Next
End Sub

Mike

"tgcali" wrote:

Hello,

I have a workbook with 250 sheets. I need to be able to hide column F
unless
cell E2 has the value "Level 1". If there is another value in E2 or it
is
blank, I need column F to be hidden. I need this on all 250 sheets. Is
this
possible?

Thanks in advance, you are all always to helpful!

tgcali


  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,533
Default Hide a column "if"?

Hi

Mike's code is working fine here.

It's difficult to figure out what is the problem, as you do not state the
entire error message.

Is any of the sheets protected?

Regards,
Per

"tgcali" skrev i meddelelsen
...
I get the error in the same place for both of them. Any suggestions?

tgcali

"Mike H" wrote:

on reflection try this instead

Sub sonic()
Dim ws As Worksheet
For x = 1 To Worksheets.Count
If Worksheets(x).Range("E2").Value < "Level 1" Then
Worksheets(x).Columns("F:F").EntireColumn.Hidden = True
End If
Next
End Sub

Mike

"tgcali" wrote:

Hello,

I have a workbook with 250 sheets. I need to be able to hide column F
unless
cell E2 has the value "Level 1". If there is another value in E2 or it
is
blank, I need column F to be hidden. I need this on all 250 sheets. Is
this
possible?

Thanks in advance, you are all always to helpful!

tgcali


  #9   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 49
Default Hide a column "if"?

Thanks! I almost got it. The column is hidden for all the sheets, but it's
not displaying when the value "Level 1" is in cell E2. You've been very
helpful and I really appreciate it.

tgcali

"Mike H" wrote:

Hi,

I've tried to replicate the error but can't so lets try again and a bit
simpler maybe.
It will work as worksheet code so right click the sheet tab of any sheet and
in the pop-up menu click 'View code'.

Paste this in on the right hand side and still in VB editor with the cursor
in the sub tap F5

Sub sonic()
For x = 1 To Worksheets.Count
If Worksheets(x).Range("E2").Value < "Level 1" Then
Worksheets(x).Columns("F:F").EntireColumn.Hidden = True
End If
Next
End Sub

Mike

"tgcali" wrote:

I get the error in the same place for both of them. Any suggestions?

tgcali

"Mike H" wrote:

on reflection try this instead

Sub sonic()
Dim ws As Worksheet
For x = 1 To Worksheets.Count
If Worksheets(x).Range("E2").Value < "Level 1" Then
Worksheets(x).Columns("F:F").EntireColumn.Hidden = True
End If
Next
End Sub

Mike

"tgcali" wrote:

Hello,

I have a workbook with 250 sheets. I need to be able to hide column F unless
cell E2 has the value "Level 1". If there is another value in E2 or it is
blank, I need column F to be hidden. I need this on all 250 sheets. Is this
possible?

Thanks in advance, you are all always to helpful!

tgcali

  #10   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default Hide a column "if"?

Now thta the problem I anticipated. The text for 'Level 1' in the worksheet
must be exactly the same text in the code.

If you've ended up hiding lots of columns you don't want to then this
routine will inhide them

Sub marine()
For x = 1 To Worksheets.Count
Worksheets(x).Columns("F:F").EntireColumn.Hidden = False
Next
End Sub

Paste it in belwo the other code and run it

Mike

"tgcali" wrote:

Thanks! I almost got it. The column is hidden for all the sheets, but it's
not displaying when the value "Level 1" is in cell E2. You've been very
helpful and I really appreciate it.

tgcali

"Mike H" wrote:

Hi,

I've tried to replicate the error but can't so lets try again and a bit
simpler maybe.
It will work as worksheet code so right click the sheet tab of any sheet and
in the pop-up menu click 'View code'.

Paste this in on the right hand side and still in VB editor with the cursor
in the sub tap F5

Sub sonic()
For x = 1 To Worksheets.Count
If Worksheets(x).Range("E2").Value < "Level 1" Then
Worksheets(x).Columns("F:F").EntireColumn.Hidden = True
End If
Next
End Sub

Mike

"tgcali" wrote:

I get the error in the same place for both of them. Any suggestions?

tgcali

"Mike H" wrote:

on reflection try this instead

Sub sonic()
Dim ws As Worksheet
For x = 1 To Worksheets.Count
If Worksheets(x).Range("E2").Value < "Level 1" Then
Worksheets(x).Columns("F:F").EntireColumn.Hidden = True
End If
Next
End Sub

Mike

"tgcali" wrote:

Hello,

I have a workbook with 250 sheets. I need to be able to hide column F unless
cell E2 has the value "Level 1". If there is another value in E2 or it is
blank, I need column F to be hidden. I need this on all 250 sheets. Is this
possible?

Thanks in advance, you are all always to helpful!

tgcali



  #11   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 49
Default Hide a column "if"?

Ok, I made sure the text was the same. On the worksheets it is all caps, so I
changed it accordingly in the code. All the sheets have column F hidden
regardless of the entry in E2. I ran the second code. All the sheets have
column F displayed.

Any thoughts?

tgcali

"Mike H" wrote:

Now thta the problem I anticipated. The text for 'Level 1' in the worksheet
must be exactly the same text in the code.

If you've ended up hiding lots of columns you don't want to then this
routine will inhide them

Sub marine()
For x = 1 To Worksheets.Count
Worksheets(x).Columns("F:F").EntireColumn.Hidden = False
Next
End Sub

Paste it in belwo the other code and run it

Mike

"tgcali" wrote:

Thanks! I almost got it. The column is hidden for all the sheets, but it's
not displaying when the value "Level 1" is in cell E2. You've been very
helpful and I really appreciate it.

tgcali

"Mike H" wrote:

Hi,

I've tried to replicate the error but can't so lets try again and a bit
simpler maybe.
It will work as worksheet code so right click the sheet tab of any sheet and
in the pop-up menu click 'View code'.

Paste this in on the right hand side and still in VB editor with the cursor
in the sub tap F5

Sub sonic()
For x = 1 To Worksheets.Count
If Worksheets(x).Range("E2").Value < "Level 1" Then
Worksheets(x).Columns("F:F").EntireColumn.Hidden = True
End If
Next
End Sub

Mike

"tgcali" wrote:

I get the error in the same place for both of them. Any suggestions?

tgcali

"Mike H" wrote:

on reflection try this instead

Sub sonic()
Dim ws As Worksheet
For x = 1 To Worksheets.Count
If Worksheets(x).Range("E2").Value < "Level 1" Then
Worksheets(x).Columns("F:F").EntireColumn.Hidden = True
End If
Next
End Sub

Mike

"tgcali" wrote:

Hello,

I have a workbook with 250 sheets. I need to be able to hide column F unless
cell E2 has the value "Level 1". If there is another value in E2 or it is
blank, I need column F to be hidden. I need this on all 250 sheets. Is this
possible?

Thanks in advance, you are all always to helpful!

tgcali

  #12   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 49
Default Hide a column "if"?

Ignore that last post of mine. Problem solved. You're a genius! Thank you so
much!

tgcali

"Mike H" wrote:

Now thta the problem I anticipated. The text for 'Level 1' in the worksheet
must be exactly the same text in the code.

If you've ended up hiding lots of columns you don't want to then this
routine will inhide them

Sub marine()
For x = 1 To Worksheets.Count
Worksheets(x).Columns("F:F").EntireColumn.Hidden = False
Next
End Sub

Paste it in belwo the other code and run it

Mike

"tgcali" wrote:

Thanks! I almost got it. The column is hidden for all the sheets, but it's
not displaying when the value "Level 1" is in cell E2. You've been very
helpful and I really appreciate it.

tgcali

"Mike H" wrote:

Hi,

I've tried to replicate the error but can't so lets try again and a bit
simpler maybe.
It will work as worksheet code so right click the sheet tab of any sheet and
in the pop-up menu click 'View code'.

Paste this in on the right hand side and still in VB editor with the cursor
in the sub tap F5

Sub sonic()
For x = 1 To Worksheets.Count
If Worksheets(x).Range("E2").Value < "Level 1" Then
Worksheets(x).Columns("F:F").EntireColumn.Hidden = True
End If
Next
End Sub

Mike

"tgcali" wrote:

I get the error in the same place for both of them. Any suggestions?

tgcali

"Mike H" wrote:

on reflection try this instead

Sub sonic()
Dim ws As Worksheet
For x = 1 To Worksheets.Count
If Worksheets(x).Range("E2").Value < "Level 1" Then
Worksheets(x).Columns("F:F").EntireColumn.Hidden = True
End If
Next
End Sub

Mike

"tgcali" wrote:

Hello,

I have a workbook with 250 sheets. I need to be able to hide column F unless
cell E2 has the value "Level 1". If there is another value in E2 or it is
blank, I need column F to be hidden. I need this on all 250 sheets. Is this
possible?

Thanks in advance, you are all always to helpful!

tgcali

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
Chg 1 "Last, First Mid" column to 3 "First", "Middle", "Last" colu JBird11002 Excel Discussion (Misc queries) 4 August 15th 08 06:31 PM
How do I change the column heading in Excel to display "A" "B" "C Thai New Users to Excel 1 November 30th 07 08:06 PM
change "true" and "false" to "availble" and "out of stock" inthestands Excel Worksheet Functions 2 July 19th 07 07:05 PM
HELP on "left","right","find","len","substitute" functions serene83 Excel Discussion (Misc queries) 5 June 27th 06 02:23 AM
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next BCB New Users to Excel 7 May 13th 06 10:02 PM


All times are GMT +1. The time now is 12:36 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"