Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro to hide rows below

I have a spreadsheet in which column A has customers' names and other columns
have other info. Some customers have only 1 row worth of info, while others
have several rows (all directly below each other). I would like to be able to
double click the customer's name and if there are multiple rows for this
customer (meaning there is no customer name directly below, but rather a few
rows down), it will hide the rows below until the next customer's name. And
another double click will unhide the rows. For example, A1 will have "Smith".
A4 will have "Johnson". A5 will have "Brown". A9 will have "Davis". If I
double click A1 it will hide rows 2-3. If I double click A5, it will hide
rows 6-8.

If anyone can help me I would be very grateful.
Thanks, Scott
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Macro to hide rows below

The Worksheet_BeforeDoubleClick event code below should do what you asked.
To install it, right click the tab at the bottom of the worksheet you want
this functionality on, select View Code from the popup menu that appears and
copy/paste the code below into the code window that appeared...

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
Dim X As Long
Dim LastRow As Long
Dim MaxRowInUse As Long
If Not Intersect(Target, Range("A:A")) Is Nothing Then
Cancel = True
If Len(Target.Value) 0 Then
For X = 1 To ActiveSheet.UsedRange.Columns.Count
LastRow = WorksheetFunction.Max(Cells(Rows.Count, X). _
End(xlUp).Row, ActiveSheet.UsedRange.Rows.Count)
If LastRow MaxRowInUse Then MaxRowInUse = LastRow
Next
For X = Target.Row + 1 To MaxRowInUse
If Len(Cells(X, "A").Value) 0 Or X = MaxRowInUse Then
If X Target.Row + 1 Or X = MaxRowInUse Then
Cells(Target.Row + 1, "A").Resize(X - Target.Row - 1 - _
(X = MaxRowInUse)).EntireRow.Hidden = _
Not Cells(Target.Row + 1, "A").EntireRow.Hidden
End If
Exit For
End If
Next
End If
End If
End Sub

--
Rick (MVP - Excel)


"Scott Marcus" <Scott wrote in message
...
I have a spreadsheet in which column A has customers' names and other
columns
have other info. Some customers have only 1 row worth of info, while
others
have several rows (all directly below each other). I would like to be able
to
double click the customer's name and if there are multiple rows for this
customer (meaning there is no customer name directly below, but rather a
few
rows down), it will hide the rows below until the next customer's name.
And
another double click will unhide the rows. For example, A1 will have
"Smith".
A4 will have "Johnson". A5 will have "Brown". A9 will have "Davis". If I
double click A1 it will hide rows 2-3. If I double click A5, it will hide
rows 6-8.

If anyone can help me I would be very grateful.
Thanks, Scott


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro code to hide rows and not calculate hidden rows bradmcq Excel Discussion (Misc queries) 0 September 1st 09 12:38 AM
Macro to hide rows lightbulb Excel Discussion (Misc queries) 4 July 11th 08 06:13 PM
Macro to hide rows? Cam Excel Programming 1 April 22nd 08 07:23 PM
macro to hide rows Mo2 Excel Programming 2 May 9th 07 12:30 PM
hide rows with macro Alen32 Excel Programming 8 May 27th 05 01:40 PM


All times are GMT +1. The time now is 10:18 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"