[font=Verdana][color=darkblue]Option[/color] [color=darkblue]Explicit[/color]
[color=darkblue]Sub[/color] test()
[color=darkblue]Dim[/color] FoundRows [color=darkblue]As[/color] Range
[color=darkblue]Dim[/color] Rw [color=darkblue]As[/color] Range
[color=darkblue]Dim[/color] Cell [color=darkblue]As[/color] Range
[color=darkblue]Dim[/color] CellCount [color=darkblue]As[/color] [color=darkblue]Long[/color]
[color=darkblue]Dim[/color] Cnt [color=darkblue]As[/color] [color=darkblue]Long[/color]
[color=darkblue]With[/color] ActiveSheet.UsedRange
[color=darkblue]For[/color] [color=darkblue]Each[/color] Rw [color=darkblue]In[/color] .Rows
CellCount = Rw.Cells.Count
[color=darkblue]For[/color] [color=darkblue]Each[/color] Cell [color=darkblue]In[/color] Rw.Cells
Cnt = Cnt + 1
[color=darkblue]If[/color] Cell.Interior.ColorIndex <> -4142 [color=darkblue]Then[/color]
[color=darkblue]Exit[/color] [color=darkblue]For[/color]
[color=darkblue]Else[/color]
[color=darkblue]If[/color] Cnt = CellCount [color=darkblue]Then[/color]
[color=darkblue]If[/color] FoundRows [color=darkblue]Is[/color] [color=darkblue]Nothing[/color] [color=darkblue]Then[/color]
[color=darkblue]Set[/color] FoundRows = Rw
[color=darkblue]Else[/color]
[color=darkblue]Set[/color] FoundRows = Union(FoundRows, Rw)
[color=darkblue]End[/color] [color=darkblue]If[/color]
[color=darkblue]End[/color] [color=darkblue]If[/color]
[color=darkblue]End[/color] [color=darkblue]If[/color]
[color=darkblue]Next[/color] Cell
Cnt = 0
[color=darkblue]Next[/color] Rw
[color=darkblue]End[/color] [color=darkblue]With[/color]
[color=darkblue]If[/color] [color=darkblue]Not[/color] FoundRows [color=darkblue]Is[/color] [color=darkblue]Nothing[/color] [color=darkblue]Then[/color]
FoundRows.Select
[color=darkblue]Else[/color]
MsgBox "No rows found...", vbInformation
[color=darkblue]End[/color] [color=darkblue]If[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
[/font]
[font=Verdana][color=green]'Force explicit declaration of variables[/color]
[color=darkblue]Option[/color] [color=darkblue]Explicit[/color]
[color=darkblue]Sub[/color] test()
[color=green]'Declare the variables[/color]
[color=darkblue]Dim[/color] FoundRows [color=darkblue]As[/color] Range
[color=darkblue]Dim[/color] Rw [color=darkblue]As[/color] Range
[color=darkblue]Dim[/color] Cell [color=darkblue]As[/color] Range
[color=darkblue]Dim[/color] CellCount [color=darkblue]As[/color] [color=darkblue]Long[/color]
[color=darkblue]Dim[/color] Cnt [color=darkblue]As[/color] [color=darkblue]Long[/color]
[color=darkblue]With[/color] ActiveSheet.UsedRange
[color=green]'Loop through each row within the used range[/color]
[color=darkblue]For[/color] [color=darkblue]Each[/color] Rw [color=darkblue]In[/color] .Rows
[color=green]'Count the number of cells in the current row[/color]
CellCount = Rw.Cells.Count
[color=green]'Loop through each cell within the current row[/color]
[color=darkblue]For[/color] [color=darkblue]Each[/color] Cell [color=darkblue]In[/color] Rw.Cells
[color=green]'Keep a count of each iteration[/color]
Cnt = Cnt + 1
[color=green]'If current cell is blank or has a value greater than 545, exit For[/color]
[color=darkblue]If[/color] Cell.Value = "" [color=darkblue]Or[/color] Cell.Value > 545 [color=darkblue]Then[/color]
[color=darkblue]Exit[/color] [color=darkblue]For[/color]
[color=darkblue]Else[/color]
[color=green]'If current cell is the last cell in the row, assign the row to an object variable[/color]
[color=darkblue]If[/color] Cnt = CellCount [color=darkblue]Then[/color]
[color=darkblue]If[/color] FoundRows [color=darkblue]Is[/color] [color=darkblue]Nothing[/color] [color=darkblue]Then[/color]
[color=darkblue]Set[/color] FoundRows = Rw
[color=darkblue]Else[/color]
[color=darkblue]Set[/color] FoundRows = Union(FoundRows, Rw)
[color=darkblue]End[/color] [color=darkblue]If[/color]
[color=darkblue]End[/color] [color=darkblue]If[/color]
[color=darkblue]End[/color] [color=darkblue]If[/color]
[color=darkblue]Next[/color] Cell
[color=green]'Re-set the count to zero[/color]
Cnt = 0
[color=green]'Go to the next row within the used range[/color]
[color=darkblue]Next[/color] Rw
[color=darkblue]End[/color] [color=darkblue]With[/color]
[color=green]'If rows have been assigned to the object variable FoundRows, select the rows.[/color]
[color=green]'Otherwise, display a message alerting the user that no rows were found[/color]
[color=darkblue]If[/color] [color=darkblue]Not[/color] FoundRows [color=darkblue]Is[/color] [color=darkblue]Nothing[/color] [color=darkblue]Then[/color]
FoundRows.Select
[color=darkblue]Else[/color]
MsgBox "No rows found...", vbInformation
[color=darkblue]End[/color] [color=darkblue]If[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
[/font]