Hi Matt;
Here you go:
Go into Scroll_Col() and adjust the addresses in the section marked.
You will notice that there is a Static variable "siCol" in Scroll_Col().
This prevents the macro from scrolling the sheet until the next time period (so the user can scroll around the spreadsheet without it automatically scrolling them back).
There is also an optional bForce parameter in Scroll_Col(). This is so you can force the sheet to scroll back to the correct column when you want, but you will need to decide when those times are.
I haven't tested it for times before 9:00 AM. I left that for you.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Scroll_Col
End Sub
Sub Scroll_Col(Optional bForce As Boolean)
Dim rStart As Range
Dim rEnd As Range
Dim rTimes As Range
Dim rNow As Range
Dim rSelection As Range
Dim rGoto As Range
Dim sh As Worksheet
Dim iCol As Integer
Static siCol As Integer
Set sh = Selection.Worksheet
With sh
'************************************
'Adjust these addresses as necessary
Set rStart = .Range("C2")
Set rEnd = .Range("CW2")
Set rNow = .Range("A2")
'************************************
Set rTimes = Range(rStart, rEnd)
On Error Resume Next
iCol = Application.WorksheetFunction.Match(CDbl(rNow.Value), rTimes, 1)
iCol = rStart.Column + iCol - 2
If bForce Or (iCol <> siCol) Then
siCol = iCol
Set rGoto = .Cells(1, iCol)
Application.EnableEvents = False
Set rSelection = Selection
Application.Goto rGoto, True
rSelection.Select
Application.EnableEvents = True
'This would be a better solution
' because it doesn't change the selection
' but it will scroll the Left Pane
' not the right pane
'ActiveWindow.ScrollColumn = iCol
End If
End With
End Sub
Bookmarks