LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default If / Else Code (hiding rows based on cell value)

If I am to assume that you only want certain rows hidden then perhaps you
should unhide all and then just hide the desired rows with this instead

Sub Hideifj1()
With Sheets("Approved Rate Review (2)")
.Rows.Hidden = False
Select Case UCase(.Range("j1"))
Case Is = "RETAIL", "MOTO": x = "17": y = "17"
Case Is = "SMALL TICKET": x = "17:19": y = "17"
Case Is = "INTERCHANGE PLUS", "APPROVED RATE REVIEW": x = "17:22": y =
"27:32"
Case Is = "DIAL PAY": x = "17:18": y = "26:33"
Case Else
MsgBox "None to Hide"
End Select
..Rows(x).Hidden = True
..Rows(y).Hidden = True
End With

--
Don Guillett
SalesAid Software

"jjones" wrote in message
...
I'm still a newbie at writing macros, but here's the situation. I've
successfully mapped data from an Access database over to a form letter in
Excel. The verbiage in the letter varies depending on the industry type
selected (options a Retail, Small Ticket, MOTO, Interchange Plus, Dial
Pay). This is stored in cell J1. Since some paragraphs are shorter than
others, I sometimes end up with extra blank rows between paragraphs
depending
on which option has been chosen. As part of my Auto_Open macro, I want
these
extra rows of blank space hidden depending on the value in J1. As I have
the
code written now, however, the next if statement overrides the previous
one,
making all but the last one irrelevant really. I've tried changing it a
couple of different ways but I just end up with compile errors. Anybody
know
how to make this work? I'm open to other ideas if this can't be
accomplished
with If statements. Here's the code I have now:


If Range("J1").Value = "Retail" Then
Sheets("Approved Rate Review (2)").Rows("17").EntireRow.Hidden = True
Else
Sheets("Approved Rate Review (2)").Rows("17").EntireRow.Hidden = False
End If
If Range("J1").Value = "Small Ticket" Then
Sheets("Approved Rate Review (2)").Rows("17:19").EntireRow.Hidden =
True
Else
Sheets("Approved Rate Review (2)").Rows("17:19").EntireRow.Hidden =
False
End If
If Range("J1").Value = "MOTO" Then
Sheets("Approved Rate Review (2)").Rows("17").EntireRow.Hidden = True
Else
Sheets("Approved Rate Review (2)").Rows("17").EntireRow.Hidden = False
End If
If Range("J1").Value = "Interchange Plus" Then
Sheets("Approved Rate Review (2)").Rows("17:22").EntireRow.Hidden =
True
Sheets("Approved Rate Review (2)").Rows("27:29").EntireRow.Hidden =
True
Else
Sheets("Approved Rate Review (2)").Rows("17:22").EntireRow.Hidden =
False
Sheets("Approved Rate Review (2)").Rows("27:29").EntireRow.Hidden =
False
End If
If Range("J1").Value = "Dial Pay" Then
Sheets("Approved Rate Review (2)").Rows("17:18").EntireRow.Hidden =
True
Sheets("Approved Rate Review (2)").Rows("26:33").EntireRow.Hidden =
True
Else
Sheets("Approved Rate Review (2)").Rows("17:18").EntireRow.Hidden =
False
Sheets("Approved Rate Review (2)").Rows("26:33").EntireRow.Hidden =
False
End If



 
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/Exposing Rows based on a cell value Tami Excel Worksheet Functions 10 July 11th 09 02:03 PM
Hiding rows based on a cell? OX_Gambit Excel Worksheet Functions 3 July 10th 09 03:05 AM
Hiding rows based value of cell within row Legion_c18 Excel Discussion (Misc queries) 0 February 22nd 08 06:01 AM
hiding rows based on cell contents Jason M Excel Discussion (Misc queries) 1 October 30th 06 04:30 PM
Hiding rows based on cell content alistair01[_4_] Excel Programming 2 February 3rd 04 01:58 PM


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