Hello all you helping ones.
Thank you in advance for reading and for your help, really appreciate it
i am trying to find the next day based on checked boxes
there are 7 checkboxes: 1 is sunday (i based it on excels weekday values), hence 7 is saturday
if the user checks e.g. the second box, which is Monday (Value = 2), and types in a date (day, month and year; splitted to 3 boxes), which is in this example a Tuesday (Value = 3), the code should find the next date of a Monday.
My Code looks like this
How do i declare the c & (DateBefore + n) Variable to find the next c(#num) variable?
I am also open for a better solution than 7 times "If Then"
Thank you in advance for reading and for your help, really appreciate it
i am trying to find the next day based on checked boxes
there are 7 checkboxes: 1 is sunday (i based it on excels weekday values), hence 7 is saturday
if the user checks e.g. the second box, which is Monday (Value = 2), and types in a date (day, month and year; splitted to 3 boxes), which is in this example a Tuesday (Value = 3), the code should find the next date of a Monday.
My Code looks like this
VBA Code:
If CheckBox1 = True Then 'Sunday is checked
c1 = 1
End If
If CheckBox2 = True Then 'Monday is checked
c2 = 1
End If
If CheckBox3 = True Then 'Tuesday is checked
c3 = 1
End If
If CheckBox4 = True Then 'Wednesday is checked
c4 = 1
End If
If CheckBox5 = True Then 'Thursday is checked
c5 = 1
End If
If CheckBox6 = True Then 'Friday is checked
c6 = 1
End If
If CheckBox7 = True Then 'Saturday is checked
c7 = 1
End If
DateBefore = Weekday(y2.Cells(x + 1, "F")) 'That is where the typed in date comes from
If c1 = 1 Or c2 = 1 Or c3 = 1 Or c4 = 1 Or c5 = 1 Or c6 = 1 Or c7 = 1 Then
n = 1
Do Until c & (DateBefore + n) = 1 [COLOR=rgb(226, 80, 65)]'the Problem is HERE, no Variable will be found, infinite loop[/COLOR]
If DateBefore + n > 7 Then
DateBefore = -7 + DateBefore
End If
n = n + 1
Loop
DateAfter = y2.Cells(x + 1, "F") + n
Else
DateAfter = y2.Cells(x + 1, "F") + 1
End If
How do i declare the c & (DateBefore + n) Variable to find the next c(#num) variable?
I am also open for a better solution than 7 times "If Then"