Sub Previous_Cluster()
Dim thiscolumn As Long, mc As Range, val1 As Double, mstring As String, lastcl As Range, firstcl As Range
With Rows(12)
Set firstcl = .Cells.Find("CLUSTER")
Set lastcl = .Cells.Find("CLUSTER", LookIn:=xlValues, lookat:=xlWhole, searchdirection:=xlPrevious)
End With
thiscolumn = ActiveCell.Column
thisrow = ActiveCell.Row
If UCase(Cells(12, ActiveCell.Column)) = "CLUSTER" Then
Set mc2 = Rows(12).Find("Cluster", after:=Cells(12, thiscolumn), LookIn:=xlValues, lookat:=xlWhole, searchdirection:=xlPrevious)
If mc2.Column < thiscolumn Then
Application.Goto Cells(thisrow, mc2.Column), Scroll:=False
Else
Application.Goto Cells(, lastcl.Column), Scroll:=True
ActiveCell.Offset(thisrow - 1).Activate
Exit Sub
End If
ElseIf UCase(Cells(12, ActiveCell.Column)) <> "CLUSTER" Then
mstring = UCase(Cells(12, thiscolumn))
If Left(mstring, 5) = "STORE" Then
val1 = Right(mstring, Len(mstring) - 5)
If Cells(12, thiscolumn - val1).Value = "CLUSTER" Then
Set mc2 = Rows(12).Find("Cluster", after:=Cells(12, thiscolumn - val1), LookIn:=xlValues, lookat:=xlWhole, searchdirection:=xlPrevious)
If mc2.Column < thiscolumn Then
Application.Goto Cells(, mc2.Column), Scroll:=True
ActiveCell.Offset(thisrow - 1).Activate
Application.Goto Cells(ActiveCell.Row, ActiveCell.Column + val1), Scroll:=False
Else
Application.Goto Cells(, lastcl.Column), Scroll:=True
ActiveCell.Offset(thisrow - 1).Activate
Application.Goto Cells(ActiveCell.Row, ActiveCell.Column + val1), Scroll:=False
Exit Sub
End If
Else
Set mc2 = Rows(12).Find("Cluster", after:=Cells(12, thiscolumn), LookIn:=xlValues, lookat:=xlWhole, searchdirection:=xlPrevious)
Application.Goto Cells(, mc2.Column), Scroll:=True
ActiveCell.Offset(thisrow - 1).Activate
Application.Goto Cells(ActiveCell.Row, ActiveCell.Column + val1), Scroll:=False
End If
ElseIf Left(mstring, 5) <> "STORE" Then
Set mc2 = Rows(12).Find("Cluster", after:=Cells(12, thiscolumn), LookIn:=xlValues, lookat:=xlWhole, searchdirection:=xlPrevious)
Application.Goto Cells(thisrow, mc2.Column), Scroll:=False
End If
End If
End Sub
Kind regards
Bookmarks