ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Hide Columns w/Change Event (https://www.excelbanter.com/excel-programming/308100-hide-columns-w-change-event.html)

Eva Shanley[_2_]

Hide Columns w/Change Event
 
Tom Ogilvy responded to the first post I sent awhile ago,
but I'm getting an error executing the code he was nice
enough to give me; "Method range of object_worksheet
failed." I've tried several things and keep getting the
error. The code hides 3 columns if "EDLC" is the
selection. Any help is greatly appreciated; the error
occurs on both "If" lines.

Sub Worksheet_Change(ByVal Target As Excel.Range)

If Application.Intersect(Target, Range("Plan Costs!e1")) _
= "Hi-Low" Then
Exit Sub
End If
If Application.Intersect(Target, Range("Plan Costs!e1")) _
= "EDLC" Then
Sheets("Period 1").Columns("M:O") _
.EntireColumn.Hidden = True

End If

End Sub


Tom Ogilvy

Hide Columns w/Change Event
 
Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Address = "$E$1" Then
If Target.Value _
= "Hi-Low" Then
Exit Sub
End If
If Target.Value _
= "EDLC" Then
Sheets("Period 1").Columns("M:O") _
.EntireColumn.Hidden = True

End If
End If
End Sub

Worked fine for me. This assumes the code is in the sheet module for sheet
Plan Costs

--
Regards,
Tom Ogilvy

"Eva Shanley" wrote in message
...
Tom Ogilvy responded to the first post I sent awhile ago,
but I'm getting an error executing the code he was nice
enough to give me; "Method range of object_worksheet
failed." I've tried several things and keep getting the
error. The code hides 3 columns if "EDLC" is the
selection. Any help is greatly appreciated; the error
occurs on both "If" lines.

Sub Worksheet_Change(ByVal Target As Excel.Range)

If Application.Intersect(Target, Range("Plan Costs!e1")) _
= "Hi-Low" Then
Exit Sub
End If
If Application.Intersect(Target, Range("Plan Costs!e1")) _
= "EDLC" Then
Sheets("Period 1").Columns("M:O") _
.EntireColumn.Hidden = True

End If

End Sub




Eva Shanley[_2_]

Hide Columns w/Change Event
 
Thanks Tom, now the code works fine. Apparently the
original If Application.Intersect(Target, Range("Plan
Costs!e1")) was causing a problem that I wasn't good
enough to figure out. Thanks again for your help.

-----Original Message-----
Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Address = "$E$1" Then
If Target.Value _
= "Hi-Low" Then
Exit Sub
End If
If Target.Value _
= "EDLC" Then
Sheets("Period 1").Columns("M:O") _
.EntireColumn.Hidden = True

End If
End If
End Sub

Worked fine for me. This assumes the code is in the

sheet module for sheet
Plan Costs

--
Regards,
Tom Ogilvy

"Eva Shanley" wrote

in message
...
Tom Ogilvy responded to the first post I sent awhile

ago,
but I'm getting an error executing the code he was nice
enough to give me; "Method range of object_worksheet
failed." I've tried several things and keep getting the
error. The code hides 3 columns if "EDLC" is the
selection. Any help is greatly appreciated; the error
occurs on both "If" lines.

Sub Worksheet_Change(ByVal Target As Excel.Range)

If Application.Intersect(Target, Range("Plan Costs!

e1")) _
= "Hi-Low" Then
Exit Sub
End If
If Application.Intersect(Target, Range("Plan Costs!

e1")) _
= "EDLC" Then
Sheets("Period 1").Columns("M:O") _
.EntireColumn.Hidden = True

End If

End Sub



.



All times are GMT +1. The time now is 01:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com