Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excell -Sorting and row hiding

Status
Not open for further replies.

Evening

Technical User
Jan 19, 2005
45
CA
I have some data in worksheet-1. In the other worksheet-2 I am reading some fields from worksheet-1. (in the worksheet-2 I have every record-row from worksheet-1, just not all fields).I am going to sort worksheet-2 based on the value in the column B (this I am doing in VBA, the workshet is write protected, nobody can delete anything)
The user has entered the number value in field A1, (example A1=10, or 20,30 etc..) before sorting has been iniciated , telling how many rows want to analyse in worksheet-2 after sorting. I want to hide the rest of the rows based on this number. So entering 20, after I sorted all rows, VBA will leave just visible, first "n" rows, the rest are hidden.
What woudl be the command for that in VBA?
 
Hmmm, did you try the macro recorder? It's not all that dificult:
Code:
Sub test()
  HideAllButNRows 15
End Sub

Sub HideAllButNRows(NRows As Long)
    Rows(NRows + 1 & ":65536").EntireRow.Hidden = True
End Sub
Of course, you will need a similar routine to unhide the rows.
 
Thanks Zathras for help, I am starting to learn a little bit more about VBA. It works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top