Excel Scroll to dated column

Simont485

Board Regular
Joined
May 19, 2018
Messages
50
HI all

I use excel for a staff rota.

The dates are from D4 across to FF4 or whatever D4 plus 365 is......but it is a long way to scroll across!
Columns AB&C are for names, information etc....these don't scroll as they are frozen(freeze panes)

I was wondering this:

I would like to enter a date, in say Cell A1, and the spreadsheet scrolls across to that date and be next to column C?

Hope that makes sense!!!
 
Hi Simon,

In order to do that we need to introduce lngToday:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim lngMatch            As Long
    Dim lngToday            As Long


    If Not Intersect(Target, Range("A1")) Is Nothing Then
        On Error Resume Next
            lngMatch = Application.Match(Range("$A$1"), Rows(4), 0)
            lngToday = Application.Match(CLng(Date), Rows(4), 0)
        On Error GoTo 0
        If lngMatch > 0 Then
            ActiveWindow.ScrollColumn = Cells(4, lngMatch).Column
        ElseIf lngToday > 0 Then
            ActiveWindow.ScrollColumn = Cells(4, lngToday).Column
        End If
    End If
End Sub

Same as previously, remember that this is a Change Event, meaning that cell A1 needs to be changed in order to be activated (e.g. select it and press delete).
 
Last edited:
Upvote 0

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,214,926
Messages
6,122,306
Members
449,079
Latest member
juggernaut24

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top