Vincent88
Active Member
- Joined
- Mar 5, 2021
- Messages
- 382
- Office Version
- 2019
- Platform
- Windows
- Mobile
Hi Guys,
My code does not work on those weekend columns. Please help to review where goes wrong.
When double click a blank cell, it will be filled with pattern. If it is already filled with pattern, it will change the cell to a blank cell. However it does not work on those weekend columns. I have a function IsWeekend.
My code does not work on those weekend columns. Please help to review where goes wrong.
When double click a blank cell, it will be filled with pattern. If it is already filled with pattern, it will change the cell to a blank cell. However it does not work on those weekend columns. I have a function IsWeekend.
TestDropDownList_2.xlsm | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | H | I | J | K | L | M | N | O | ||||||||
1 | MDate | Attendance | 1-Feb | 2-Feb | 3-Feb | 4-Feb | 5-Feb | 6-Feb | 7-Feb | 8-Feb | |||||||
2 | Date | Summary | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | |||||||
3 | Larry Q | T:16 L:0.5 D:2.5 E:0 N:0 | G | G | G | D | N | D1 | D3 | ||||||||
4 | Mandy H | T:16 L:0.5 D:3.5 E:0 N:0 | D | K | D | K | K | K | |||||||||
5 | John G | T:16 L:0 D:1 E:2 N:0 | D | ||||||||||||||
6 | Zita V | T:16 L:1 D:2 E:0 N:1 | g | ||||||||||||||
7 | Peter B | T:16 L:2 D:1 E:0 N:0 | AL | ||||||||||||||
8 | Nacy L | T:16 L:0 D:3 E:0 N:2 | D | G | N | N | D | ||||||||||
202202 |
Cells with Data Validation | ||
---|---|---|
Cell | Allow | Criteria |
A2 | List | =Data!$P$2:$P14 |
A3 | List | =Data!$P$2:$P$14 |
A4 | List | =Data!$P$2:$P$13 |
A5:A6 | List | =Data!$P$2:$P$12 |
A7 | List | =Data!$P$2:$P$11 |
A8 | List | =Data!$P$2:$P$10 |
VBA Code:
Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
If Sh.Name = "Data" Then Exit Sub
On Error Resume Next
Dim lr As Long
Dim Lc As Long
lr = Range("A" & Rows.Count).End(xlUp).Row
Lc = Cells(1, Columns.Count).End(xlToLeft).Column
Dim rngArea As Range
Set rngArea = Range(Cells(3, 8), Cells(lr, Lc))
Debug.Print rngArea.Address
If Not Intersect(Target, rngArea) Is Nothing Then
Cancel = True
If Not IsEmpty(Target.Value) Then Exit Sub
If Target.Interior.Pattern = xlNone = True Then
With Target.Interior
.Pattern = xlPatternUp
.PatternColor = RGB(166, 166, 166)
End With
Else
If Target.Interior.Pattern = xlNone = False Then
If IsWeekend(Cells(1, Target.Column)) = False Then
Target.Interior.Pattern = xlNone
Else
If IsWeekend(Cells(1, Target.Column)) = True Then
Target.Interior.Pattern = xlNone
Target.Interior.Color = RGB(255, 245, 230)
End If
End If
End If
End If
End If
End Sub
Public Function IsWeekend(InputDate As Date) As Boolean
Select Case Weekday(InputDate)
Case vbSaturday, vbSunday
IsWeekend = True
Case Else
IsWeekend = False
End Select
End Function