Solved

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

Posted on 2011-09-11
4
205 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 42

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 42

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

724 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