Move view to column with todays date a row

Gavlaar

New Member
Joined
May 8, 2024
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Hi, looking for some help if possible.

On row2 of a sheet I have dates in range F2: AGP2, I'm trying to write some code that will move the current view to show the column with todays date in it and have it showing to the hand side of the screen (plus to show 4 cells left as well as that will mean the previous day is also visible) but without moving the current view vertically, just moving the view horizontally.
 

Attachments

  • IMG_6762.jpg
    IMG_6762.jpg
    207.7 KB · Views: 8

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
I have this code working as I would want but I can not figure out how to have the column where I would like it on the screen.
VBA Code:
Sub Today()

Dim c As Long

Dim r As Range

Set r = ActiveSheet.Range("F2: AGP2")

On Error Resume Next

c = Application.WorksheetFunction.Match(CLng(Date), r, 0)

On Error GoTo 0

If c Then

ColumnLetter = Split(Cells(1, c + 6).Address, "$")(1) ' this is the column you want to move too!

ActiveSheet.Range(ColumnLetter & ActiveCell.Row).Activate

Else

MsgBox "Not Found"

End If

End Sub
 
Upvote 0
Perhaps this will help:
VBA Code:
Sub Today()
    Dim fRng As Range
    Dim rng As Range
   
    Set rng = Range("F2:AGP2")
    Set fRng = rng.Find(Date, , , xlWhole)
   
    If Not fRng Is Nothing Then
        Application.Goto Columns(fRng.Column - 4), True
    Else
        MsgBox "Not Found"
    End If
End Sub
 
Upvote 0
Thanks for that Georgiboy!
at the moment I always get a "Not Found" so far, the dates are calculated in a formula.
 
Upvote 0
Thanks for that Georgiboy!
at the moment I always get a "Not Found" so far, the dates are calculated in a formula.
Please post the formula you use in calculating your dates.
 
Upvote 0
Change:
VBA Code:
Set fRng = rng.Find(Date, , , xlWhole)
To:
VBA Code:
Set fRng = rng.Find(Date, , xlValues, xlWhole)
 
Upvote 0
it is + the cell to the left +1
with the first cell being a typed in date
So how is the very first date to the most left being entered/calculated?
What is the exact value/formula in that cell?
What I am really trying to ascertain is whether or not you have a complete, valid date in that cell, or just the day number (so a partial date).

BTW, the image in your original post is unreadable, so not helpful at all in aiding in your question.
 
Upvote 0
I am probably in the minority but I am quite partial to using Match for this sort of thing and since you said you had that working give this a try.

VBA Code:
Sub MoveToToday()

    Dim c As Range
    Dim r As Range
    
    Set r = ActiveSheet.Range("F2: AGP2")
    
    On Error Resume Next
    With Application
        Set c = .Index(r, 0, .Match(CLng(Date), r, 0))
    End With
    On Error GoTo 0
    
    If Not c Is Nothing Then
        ActiveWindow.ScrollColumn = c.Offset(, -4).Column
    Else
        MsgBox "Not Found"
    End If

End Sub
 
Upvote 1
Solution

Forum statistics

Threads
1,216,117
Messages
6,128,935
Members
449,480
Latest member
yesitisasport

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