Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default hisind rows with an if statement

I would like to be able to hide a number of rows based on the response to a
question..

The response to the question is a list box with either "yes" or "no" as the
choices.. If the response = "no" then I would like to hide the next 3 rows,
otherwise do nothing..

Is there a "hide" command of some sort that I can use as part of an IF
statement or is this going to require a macro ?


--
Thanks

Larry
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,203
Default hisind rows with an if statement

Requires a macro, specifically a Worksheet_Change() event macro:
Assuming your "YES/NO" choice is in column A the code below will work
unchanged, otherwise edit as needed after copying.

To put it to work in your workbook (make a copy to test with)
Open the test copy, select the sheet this needs to work with and then
right-click on its name tab and choose [View Code] from the list. Copy the
code below and paste it into the module presented to you. Close the VB
Editor and give it a test run.

Private Sub Worksheet_Change(ByVal Target As Range)
'change as required
Const colWithYesNoEntry = "A"
Dim CO As Integer

If Target.Cells.Count = 1 And Target.Column = _
Range(colWithYesNoEntry & "1").Column Then
' single cell changed in proper column
Application.ScreenUpdating = False
If UCase(Trim(Target)) = "YES" Then
'is YES, unhide next 3 rows
For CO = 1 To 3
Target.Offset(CO, _
0).EntireRow.Hidden = False
Next
'go down to next row
Target.Offset(1, 0).Activate
ElseIf UCase(Trim(Target)) = "NO" Then
'assumed to be NO
'hide next 3 rows
For CO = 1 To 3
Target.Offset(CO, _
0).EntireRow.Hidden = True
Next
'and move down below the 3 hidden rows
Target.Offset(4, 0).Activate
End If
End If
End Sub




"Larry Fitch" wrote:

I would like to be able to hide a number of rows based on the response to a
question..

The response to the question is a list box with either "yes" or "no" as the
choices.. If the response = "no" then I would like to hide the next 3 rows,
otherwise do nothing..

Is there a "hide" command of some sort that I can use as part of an IF
statement or is this going to require a macro ?


--
Thanks

Larry

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
Rows vb statement Rick Excel Discussion (Misc queries) 1 April 25th 10 11:37 PM
hiding rows with an if statement Larry Fitch Excel Worksheet Functions 0 April 4th 10 03:50 PM
if statement using rows and columns Joe@Phoenix Excel Discussion (Misc queries) 5 August 31st 09 09:37 PM
IF statement inserting new rows PVANS Excel Programming 10 July 30th 09 09:55 AM
Deleting Rows in Case Statement SeventhFloorProfessor Excel Programming 2 May 19th 09 04:32 PM


All times are GMT +1. The time now is 06:08 PM.

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"