'
' Hide All rows where the column content is equal to the current Cell Macro
' It assumes you are already on the Events sheet!
'
' Macro created 13-2-2006 by Bob Becker Hof (HP)
' Tested with Excel 2003 and EVE 2.30 xls output format
' Changed Row and Column variables from Integer to Long to avoid Overflow if more then 32767 rows
' Disable screen updates during the hiding process of the matching rows and enable it once we are done
' Show progress while being busy by changing the window headers
' Moved the real code to a function which is called by the original (sub) macro. The sub will call the function
' 	with a parameter "Interactive". The function itself does nothing with it but. It has been splitted to make it conform the other 
'		macros. Nothing more.
' If the length of the file is huge the progress indicator at the top get an overflow (>200 characters) and get into the debugger.
'   We now check the length of the variable and if it exceeds 200 we take the last 197 characters and put three dots at the start.
'

Sub HideThisAndSimilarRowsLikeCurrentCell()
		Function_HideThisAndSimilarRowsLikeCurrentCell("Interactive")
End Sub 

Function Function_HideThisAndSimilarRowsLikeCurrentCell(mode)

Dim crow As Long
Dim ccol As Long
Dim lasrow As Long
Dim lascol As Long
Dim trow As Long
Dim tcol As Long
Dim frow As Long
Dim findstring As String
Dim curstring As String
Dim stepsize As Double
Dim steprows As Integer
Dim stepperc As String
Dim currentcaption As String

    crow = ActiveCell.Row
    ccol = ActiveCell.Column
    findstring = ActiveCell.Value
    lasrow = ActiveCell.SpecialCells(xlLastCell).Row
    lascol = ActiveCell.SpecialCells(xlLastCell).Column
    tcol = ccol
    trow = lasrow
    foundnewrow = True

' Temporarily stop screen updates to speed up the process
    Application.ScreenUpdating = False
    currentcaption = ActiveWorkbook.Windows(1).Caption    ' Save current Window Caption

'
' Loop from the last row for this column and find all matching cells within this column and hide them
'

' We would like to see how we are progressing even though we disable the screen updates...
    stepsize = (lasrow - 1) / 10                           ' We display info each 10th time
    steprows = 0

    For trow = lasrow To 2 Step -1
        
        steprows = steprows + 1
'
' Do we have to show where we are?
'
        If (steprows > stepsize) Then
            stepperc = currentcaption & " ==> HideThisAndSimilarRowsLikeCurrentCell progress... " & Int((lasrow - trow) / lasrow * 100) & " %"
            if len(stepperc) > 200 Then
            	stepperc = "..." & right(stepperc,197)
            End If
            Application.ScreenUpdating = True
            ActiveWorkbook.Windows(1).Caption = stepperc
            Application.ScreenUpdating = False
            steprows = 0                                    ' Count our steps again for our next intermediate result
        End If
        
        Cells(trow, tcol).Select
        curstring = ActiveCell.Value
        If curstring = findstring Then
            Rows(trow).Select
            Selection.EntireRow.Hidden = True
        End If
        
    Next

' Enable original windows caption again
    ActiveWorkbook.Windows(1).Caption = currentcaption
    
'
' Loop from the Cell we started minus one backwards to row 1 until we find a cell that does not match and is not hidden
'
    For trow = crow To 1 Step -1
        Cells(trow, tcol).Select
        curstring = ActiveCell.Value
        If curstring <> findstring And curstring <> "" Then
            For frow = trow To 2 Step -1
                If Not Range(Cells(frow, ccol).Address).EntireRow.Hidden Then
                    Cells(frow, ccol).Select
                    frow = 1
                    trow = 1
                End If
            Next
        End If
    Next
    
' Enable screen updates again
    Application.ScreenUpdating = True
    
'
' Reset the last Cell
'
    ActiveSheet.UsedRange

End Function
