'
' The purpose of this macro is to find a yellow marked cell on a worksheet
' We will only search for a yellow marked cell if the tab of this worksheet is marked yellow as well
' or when it is the Overview sheet
'
' Macro created 18-06-2007 by Bob Becker Hof (HP)
' Tested with Excel 2010 and iNex 1.21 xls output format
'

Sub Find_Yellow_Interior()
Dim crow As Long
Dim ccol As Long
Dim lasrow As Long
Dim lascol As Long
Dim Area As String

crow = ActiveCell.Row
ccol = ActiveCell.Column
lasrow = ActiveCell.SpecialCells(xlLastCell).Row
lascol = ActiveCell.SpecialCells(xlLastCell).Column

'
' If the Tab of this worksheet is not yellow there should not be any
' yellow marked cells on this sheet so we stop directly
'
If Not (ActiveSheet.name = "Overview") Then
   If Not (ActiveSheet.Tab.ColorIndex = 6) Then
    GoTo Finish
   End If
End If

'
' First review current row, next column to the of this row for a yellow marked cell
' But only if the current column is not the last column on this row
'
If Not (ccol + 1 > lascol) Then
  Area = Cells(crow, ccol + 1).Address & ":" & Cells(crow, lascol).Address
  Find_Yellow_Interior_Range (Area)
End If

'
' If we have changed position we have found a new yellow marked cell so we can stop
'
If Not (ccol = ActiveCell.Column And crow = ActiveCell.Row) Then
  GoTo Finish
End If

'
' If our current row is not the last row start searching from the next row first column until the
' far end of the worksheet for a yellow marked cell
'
If Not (crow + 1 > lasrow) Then
  Area = Cells(crow + 1, 1).Address & ":" & Cells(lasrow, lascol).Address
  Find_Yellow_Interior_Range (Area)
End If

'
' If we have changed position we have found a new yellow marked cell so we can stop
'
If Not (ccol = ActiveCell.Column And crow = ActiveCell.Row) Then
  GoTo Finish
End If

'
' If our current row is not the top row start searching from the top left row until the row above
' our current row
'
If Not (crow = 1) Then
  Area = Cells(1, 1).Address & ":" & Cells(crow - 1, lascol).Address
  Find_Yellow_Interior_Range (Area)
End If

'
' If we have changed position we have found a new yellow marked cell so we can stop
'
If Not (ccol = ActiveCell.Column And crow = ActiveCell.Row) Then
  GoTo Finish
End If

'
' If our current column is not 1 then search from the current row column 1 towards our current column
' for a new yellow marked cell
'
If Not (ccol = 1) Then
  Area = Cells(crow, 1).Address & ":" & Cells(crow, ccol - 1).Address
  Find_Yellow_Interior_Range (Area)
End If

'
' No need to check anything here
'

Finish:
End Sub


'
' Search the range as specified by Area (format A1:D2) for a cell
' having the interior set to 6 (= Yellow)
' If found unhide the row and column for this cell (Just in case it is set)
' and move the cursor to that cell
'
Sub Find_Yellow_Interior_Range(Area)
Dim FoundCell As range

'MsgBox (Area)

'just in case there's other stuff that's been specified
Application.FindFormat.Clear
Application.FindFormat.Interior.ColorIndex = 6

With ActiveSheet
    Set FoundCell = .range(Area).Find(What:="", _
    SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, _
    MatchCase:=False, _
    SearchFormat:=True)
    If FoundCell Is Nothing Then
        Exit Sub
    Else
        FoundCell.EntireColumn.Hidden = False
        FoundCell.EntireRow.Hidden = False
        Application.Goto FoundCell, Scroll:=False
    End If
End With

End Sub
