LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Hiding and unhiding rows with if statement macro

If this were my problem, I would have each of the two combo box's click or
change event record an associated value to a specified location on the
spreadsheet. Then I'd have a separate "hider decider" column (probably
hidden) with formulas to look at the two indicator spots. Each formula would
look at the combination of the two values and decide whether to return a 1 or
0. Then I would loop through the pertinent cells in that column to hide or
unhide the individual rows appropriately.

I've used that approach to handle similar tasks, and with some fairly
complex formulas to decide about different combinations of factors. Works
like a charm.

"Johanna Gronlund" wrote:

Hello,

I have a problem that I am unable to solve. I wondered if there is anyone
who could think of a solution.

I have two comboboxes (ComboBox1 and ComboBox2). In the first combobox the
user can select whether they want to view rows 37-127 or rows 128-207. The
code currently looks like this:

Sub ComboBox1_Change()
' Combobox Value Is changed
varData = Range("P21").Value2
' unhide ranges
On Error GoTo 100
Application.ScreenUpdating = False
Sheet3.Range("A37:A127").EntireRow.Hidden = False
Sheet3.Range("A128:A207").EntireRow.Hidden = True
Sheet3.Range("A102, A183, A107:A112, A188:A193").EntireRow.Hidden =
True

Select Case varData
Case 2
Sheet3.Range("A128:A207").EntireRow.Hidden = False
Sheet3.Range("A37:A127").EntireRow.Hidden = True
Sheet3.Range("A102, A183, A107:A112, A188:A193").EntireRow.Hidden =
True

End Select
100:
Application.ScreenUpdating = True
End Sub

In the 2nd combobox the user can select whether they want to enter their
values on rows:
- A51:A52 (if the first option is selected in ComboBox1) or A145 (if the
second option is selected in ComboBox1)
OR
- A43:A50 (if the first option is selected in ComboBox1) or A137:A144 (if
the second option is selected in ComboBox1)

So, there are four different combinations of hidden/unhidden rows. My
current solution does not work because when the user makes their 2nd
selection, it unhides previously unhidden rows, eg either A51:A52, A145,
A43:A50 or A137:A144.

Is there a way to have an if statement in the macro(s) that does the
following:
- P21=1 and A33=1, rows A128:A207 AND A51:A52 are hidden
- P21=1 and A33=2, rows A128:A207 AND A43:A50 are hidden
- P21=2 and A33=1, rows A37:A127 AND A145 are hidden
- P21=2 and A33=1, rows A37:A127 AND A137:A144 are hidden
- rows A102, A183 A107:A112 and A188:A193 should always be hidden
- all other rows should be unhidden, including the previously hidden selection

Also, currently I have two macros attached to the two dropdown menus that
update cells P21 and A33. If the if statements can combine the two macros,
where would I attach the macro? Not on the combobox I assume. Would I need an
additional button?

I would very much appreciate your help!

Johanna

 
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
hiding/unhiding rows Art Excel Worksheet Functions 1 March 16th 10 05:00 PM
Hiding and unhiding rows Johanna Gronlund Excel Programming 8 February 2nd 10 01:40 PM
Macro for hiding/unhiding a set of rows GoBucks[_2_] Excel Programming 3 April 23rd 09 12:55 AM
unhiding and hiding rows Paul_of_Abingdon[_2_] Excel Discussion (Misc queries) 2 March 6th 08 03:22 PM
Hiding/Unhiding rows Arne Hegefors Excel Programming 2 July 21st 06 08:19 AM


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