Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2011-09-11
4
Medium Priority
?
210 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 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
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.

596 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