Solved

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

Posted on 2011-09-11
4
196 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
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.

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now