I am trying to automate an annual leave calendar. I got stuck on looking for a value grater than 20% within a given Range.
Since the code puts an X in the range, I thought i could check on the range (row 4) for the value. I cant get it to work.Thanks in advance for your help.
Code:
Sub NewTest()
Application.ScreenUpdating = False
Dim oSet As Integer
Dim StartDate As Range, EndDate As Range
oSet = 1
Dim q1 As Range, cel As Range, iName As Range
Set q1 = Sheets("Calendar").Range("B3:QO3")
Set iName = Sheets("Input").Range(Sheets("Input").Range("A6"), Sheets("Input").Range("A6").End(xlDown))
For Each cel In iName
Do Until cel.Offset(, oSet).Column() = 12
If cel.Row() = 76 Then
Debug.Print
End If
Set StartDate = q1.Find(What:=cel.Offset(, oSet))
Set EndDate = q1.Find(What:=cel.Offset(, oSet + 1))
If cel.Offset(, oSet) = "" Then
GoTo Skip
Else
Sheets("Calendar").Range(Sheets("Calendar").Cells(cel.Row() - 1, StartDate.Column()), Sheets("Calendar").Cells(cel.Row() - 1, EndDate.Column())).Value = "X"
'***UPDATE SECOND OPTION
' If Sheets("Calendar").Range(StartDate.Offset(1, 0), EndDate.Offset(1, 0)) >= 0.2 Then ' ***This works but only checks on the first given date
If Sheets("Calendar").Range(Sheets("Calendar").Cells(4 - 1, StartDate.Column()), Sheets("Calendar").Cells(4 - 1, EndDate.Column())).Value >= 0.2 Then '' Im trying to do something like this, where it will check between the first given date, the second date, and all cells in between the given range
Sheets("Calendar").Range(Sheets("Calendar").Cells(cel.Row() - 1, StartDate.Column()), Sheets("Calendar").Cells(cel.Row() - 1, EndDate.Column())).Value = ""
cel.Offset(, oSet).Interior.Color = 65535
cel.Offset(, oSet + 1).Interior.Color = 65535
cel.Offset(, oSet).Value = cel.Offset(, oSet + 35)
cel.Offset(, oSet + 1).Value = cel.Offset(, oSet + 36)
Application.ScreenUpdating = True
If cel.Offset(, oSet) = "" Then
GoTo Skip
Else
Set StartDate = q1.Find(What:=cel.Offset(, oSet))
Set EndDate = q1.Find(What:=cel.Offset(, oSet + 1))
Sheets("Calendar").Range(Sheets("Calendar").Cells(cel.Row() - 1, StartDate.Column()), Sheets("Calendar").Cells(cel.Row() - 1, EndDate.Column())).Value = "X"
Application.ScreenUpdating = False
End If
Else
End If
'***UPDATE THIRD OPTION
'If StartDate.Offset(1, 0).Value >= 0.2 Then
If Sheets("Calendar").Range(Sheets("Calendar").Cells(cel.Row() - cel.Row() + 3, StartDate.Column()), Sheets("Calendar").Cells(cel.Row() - cel.Row() + 3, EndDate.Column())).Value >= 0.2 Then
Sheets("Calendar").Range(Sheets("Calendar").Cells(cel.Row() - 1, StartDate.Column()), Sheets("Calendar").Cells(cel.Row() - 1, EndDate.Column())).Value = ""
cel.Offset(, oSet).Interior.Color = 5296274
cel.Offset(, oSet + 1).Interior.Color = 5296274
cel.Offset(, oSet).Value = cel.Offset(, oSet + 45)
cel.Offset(, oSet + 1).Value = cel.Offset(, oSet + 46)
Application.ScreenUpdating = True
If cel.Offset(, oSet) = "" Then
GoTo Skip
Else
Set StartDate = q1.Find(What:=cel.Offset(, oSet))
Set EndDate = q1.Find(What:=cel.Offset(, oSet + 1))
Sheets("Calendar").Range(Sheets("Calendar").Cells(cel.Row() - 1, StartDate.Column()), Sheets("Calendar").Cells(cel.Row() - 1, EndDate.Column())).Value = "X"
Application.ScreenUpdating = False
End If
Exit Sub
Else
End If
End If
Skip:
oSet = oSet + 2
Loop
oSet = 1
'
Next cel
Since the code puts an X in the range, I thought i could check on the range (row 4) for the value. I cant get it to work.Thanks in advance for your help.