I've made a diary view, it all seems to work well, however, I want to be able to make the diary view go to a specified date using some vba.
Currently, I have a week on show, a next week and previous week buttons, this changes the view by 1 week either way.
I would like to have a button that allows the user to click, specify a date and have the weekly view show the week that contains that date.
I don't have any code at this point, as I have no idea where to start. the code for the next week button is below along with an image of the current weekly view. Hope this helps answer my question.
Sub NextWeek()
Dim viewerCol, viewerRow As Long
StopCalc
viewerRow = 2
With Sheet8
For viewerCol = 4 To 10
.Cells(viewerRow, viewerCol).value = .Cells(viewerRow, viewerCol).value 7
Next
End With
ResetCalc
WeeklyProjectView_Load
End Sub
View of columns B:M, D:J contain Monday:Sunday
CodePudding user response:
This will work:
Option Explicit
Sub WeekContainingDay()
Dim InputDay As Date
Dim ViewerCol As Byte
Dim ViewerRow As Byte
'StopCalc
ViewerRow = 2
InputDay = InputBox("Type date in desired week", "Week Selection", Format(Date, "dd mmm"))
Do Until Weekday(InputDay, vbMonday) = 1
InputDay = InputDay - 1
Debug.Print InputDay
Loop
With Sheet8
For ViewerCol = 4 To 10
.Cells(ViewerRow, ViewerCol).Value = InputDay ViewerCol - 4
Next ViewerCol
End With
'ResetCalc
'WeeklyProjectView_Load
End Sub