Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 211
Default code to hide hides too much

Hello I want to hide columns "e" and "f" if cells C7 says anything else
than "Web System ". I created the code below and it works except that it also
hides columns "e" and "f" if I enter anything in in row 7 thanks

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 3 And (Target.Value = "Web System") Then
Columns("E:F").Hidden = False
Else: Columns("E:F").Hidden = True
End If
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,091
Default code to hide hides too much

You're checking only for a change in Column C. There is no reference to row
7. Your code should look something like this:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 3 And Target.Row = 7 Then
If Target.Value = "WS" Then
Columns("E:F").Hidden = False
Else
Columns("E:F").Hidden = True
End If
End If
End Sub

Tyro


"Marilyn" wrote in message
...
Hello I want to hide columns "e" and "f" if cells C7 says anything else
than "Web System ". I created the code below and it works except that it
also
hides columns "e" and "f" if I enter anything in in row 7 thanks

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 3 And (Target.Value = "Web System") Then
Columns("E:F").Hidden = False
Else: Columns("E:F").Hidden = True
End If
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,290
Default code to hide hides too much


The following does what you requested.
However, I doubt it is what you want?...
'--
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$E$7" Then
If (Target.Value = "Web System") Then
Columns("E:F").Hidden = False
Else
Columns("E:F").Hidden = True
End If
End If
End Sub
'--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)


"Marilyn"
wrote in message
Hello I want to hide columns "e" and "f" if cells C7 says anything else
than "Web System ". I created the code below and it works except that it also
hides columns "e" and "f" if I enter anything in in row 7 thanks

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 3 And (Target.Value = "Web System") Then
Columns("E:F").Hidden = False
Else: Columns("E:F").Hidden = True
End If
End Sub
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default code to hide hides too much

I'd use something like:

Private Sub Worksheet_Change(ByVal Target As Range)
if target.cells.count 1 then exit sub 'one cell at a time
if intersect(target, me.range("C7")) is nothing then exit sub

if lcase(target.value) = lcase("web system") then
me.columns("E:F").hidden = true
else
me.columns("E:F").hidden = false
end if

End Sub

You could actually replace that if/then/else with this:

me.columns("E:F").hidden = cbool(lcase(target.value) = lcase("web system"))



Marilyn wrote:

Hello I want to hide columns "e" and "f" if cells C7 says anything else
than "Web System ". I created the code below and it works except that it also
hides columns "e" and "f" if I enter anything in in row 7 thanks

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 3 And (Target.Value = "Web System") Then
Columns("E:F").Hidden = False
Else: Columns("E:F").Hidden = True
End If
End Sub


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,091
Default code to hide hides too much

Correction: The "WS" in the code should be "Web System"

Tyro

"Tyro" wrote in message
...
You're checking only for a change in Column C. There is no reference to
row 7. Your code should look something like this:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 3 And Target.Row = 7 Then
If Target.Value = "WS" Then
Columns("E:F").Hidden = False
Else
Columns("E:F").Hidden = True
End If
End If
End Sub

Tyro




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/code to hide rows Smatass Excel Worksheet Functions 1 September 25th 07 01:57 AM
Hide VBA code help GerryK Excel Worksheet Functions 3 May 30th 07 09:47 PM
How to hide VB code from Excel file Anift Setting up and Configuration of Excel 3 December 19th 06 01:43 PM
When i hide columns it hides whole sheet CathyL Excel Discussion (Misc queries) 1 June 15th 06 07:51 PM
Hide Code tannersnonni Excel Discussion (Misc queries) 0 July 28th 05 01:06 AM


All times are GMT +1. The time now is 05:18 AM.

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"