Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Paul
 
Posts: n/a
Default Insert macro into formula

I would like to insert a macro into my worksheet that will hide or unhide
rows of the worksheet based on the input value of a cell.

For example, if the user enters "Y" (for yes) in a cell, I want the next two
rows below the input cell to unhide. If the user enters "N" or "N/A", I want
the next two rows to remain hidden.

Thanks!
  #2   Report Post  
Bob Phillips
 
Posts: n/a
Default

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range("H1:H10")) Is Nothing Then
With Target
If .Value = "Y" Then
.Offset(1, 0).Resize(2).EntireRow.Hidden = False
ElseIf .Value = "N" Or .Value = "N/A" Then
.Offset(1, 0).Resize(2).EntireRow.Hidden = True
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.




--
HTH

Bob Phillips

"Paul" wrote in message
...
I would like to insert a macro into my worksheet that will hide or unhide
rows of the worksheet based on the input value of a cell.

For example, if the user enters "Y" (for yes) in a cell, I want the next

two
rows below the input cell to unhide. If the user enters "N" or "N/A", I

want
the next two rows to remain hidden.

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
How do I insert a line feed in a formula? TX_KniveS Excel Worksheet Functions 5 October 31st 08 12:55 AM
How to insert carriage return in the middle of a text formula to . Dave Excel Discussion (Misc queries) 2 March 17th 05 02:14 PM
insert a new cell into an existing formula Debbie Excel Discussion (Misc queries) 3 March 14th 05 06:46 PM
repeat macro formula to all cells dave glynn Excel Discussion (Misc queries) 8 March 10th 05 08:42 PM
Challenging Charting C TO Charts and Charting in Excel 0 January 17th 05 06:57 PM


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