default_name
Board Regular
- Joined
- May 16, 2018
- Messages
- 180
- Office Version
- 365
- 2016
- Platform
- Windows
- MacOS
Hey everyone!
I am currently trying to implement a function into a workbook that has many worksheets.
Each worksheet has individual dates stored in cells E1:R1.
I have tried to play around with it and I feel like I am getting nowhere. Coding really isn't a strong trait I possess (as you will see below).
My garbage attempt
I hope that my request makes sense.
If not, please let me know and I can try to clarify.
I am currently trying to implement a function into a workbook that has many worksheets.
Each worksheet has individual dates stored in cells E1:R1.
- When the workbook is opened I want the code to immediately run (so I put it in the Workbook_Open sub).
- The code looks through each worksheet.
- If today's date is found on one of the worksheets (in E1:R1), then I would like it to then check for the following conditions:
- If today's date appears between E1:K1 of that sheet, then I would like to hide column U
- If today's date appears between L1:R1 of that sheet, then I would like to hide column T
- If today's date is not found in E1:R1 of a worksheet, then I would like to hide both columns T and U and move on to the next sheet.
- If today's date is found on one of the worksheets (in E1:R1), then I would like it to then check for the following conditions:
I have tried to play around with it and I feel like I am getting nowhere. Coding really isn't a strong trait I possess (as you will see below).
My garbage attempt
VBA Code:
Private Sub Workbook_Open()
Dim currentDate As Date
currentDate = Date
For Each ws In Worksheets
With ws
If Date = ws.Range("E1:K1").Find(Date, , , xlWhole, , , , , False)
Then
Columns("T:T").Select
Selection.EntireColumn.Hidden = False
Columns("U:U").Select
Selection.EntireColumn.Hidden = True
ElseIf Date = ws.Range("L1:R1").Find(Date, , , xlWhole, , , , , False)
Columns("T:T").Select
Selection.EntireColumn.Hidden = True
Columns("U:U").Select
Selection.EntireColumn.Hidden = False
Else
Columns("T:T").Select
Selection.EntireColumn.Hidden = True
Columns("U:U").Select
Selection.EntireColumn.Hidden = True
End If
End With
Next ws
End Sub
I hope that my request makes sense.
If not, please let me know and I can try to clarify.