Solved

How to hide a block of rows in middle of spreadsheet with excel vba

Posted on 2011-09-11
4
201 Views
Last Modified: 2012-05-12
I have a spreadsheet that displays Physician specialties.  There are 160 some physician specialties so I need to give the user the ability to only see the top 50 specialties.  I've done this with the following code:
Private Sub cmdtop50_Click()
    Dim wks As Worksheet
    Dim lastrow As Long

    Set wks = ActiveSheet

    lastrow = Range("A" & Rows.Count).End(xlDown).row
    wks.Rows("61:" & lastrow).Hidden = True
   
End Sub

THe spreadsheet has a graphical design for the first 150 rows.  Then there is raw data and the graphical design portion consists of v-lookups to the raw data (I did not design this).  So when I hide rows after row 60 I just go ahead and hide everything -- all the way to the bottom of the spreadsheet.  That works ok but it is pretty bad code I have to admit.  Now I need to create a click event that allows the user to SEE all 150 specialties.  I'd like to let the user see the 150 specialties without seeing the raw data.  So what I'd like is to unhide rows 61 through 150, but keep hidden the rows from 150 to the last row of the spreadsheet. Is there a way to do this without actually entering row numbers?

Thanks,
0
Comment
Question by:dkcoop03
  • 2
4 Comments
 
LVL 41

Expert Comment

by:dlmille
ID: 36520323
You do need to specify row numbers, unless there's a gap between the specialities and raw data that you could build a range on.

The unhidE command would be:

wks.rows("61:150").Hidden = false

Dave
0
 
LVL 41

Accepted Solution

by:
dlmille earned 250 total points
ID: 36520895
A couple other comments.  Your cmdTop50_click() routine could use a couple tweaks.

Try this:

Private Sub cmdtop50_click
dim wks as worksheet
dim lastRow as long

  set wks = activesheet
  wks.Rows("61:" & wks.Rows.Count).Hidden = True
end Sub

to unhide (per my prior post) - use this:

Private sub cmdShowSpecialities_Click()
dim wks as worksheet

  set wks = activesheet
  wks.Range("61:150").Hidden = False
end Sub

Cheers,

Dave
0
 
LVL 6

Expert Comment

by:TinTombStone
ID: 36521229
Why not just use Excel Outlining function?

Select the rows, then goto: Data Tab, Outline Group, Group

Or in 2003

Select the rows, then goto: Data Menu, Group and Outline, Group

It's worth playing with and no code to worry about
0
 

Author Closing Comment

by:dkcoop03
ID: 36523242
Thanks again Dave.  I have to do all of this in code based on events so the outlining function was not an option.  This workbook was created by my boss so I have to work with his material.   I was a little sticky on the show all piece but this will work great.
0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question