Count down the loops by a number entered on a UserForm until "0"

Creation6000ya

New Member
Joined
Nov 2, 2019
Messages
3
Good afternoon Mr. Excel,

I have a workbook that runs through code using a UserForm with several TextBoxes and a couple of ComboBoxes. The below code shows what I have so far but I am trying to figure out how to Loop through the code a specific number of times based on a value the user will enter on the UserForm. The code that is indented is what I currently have and it works well for what it is. The small section of code that is justified to the left is what I have added to try and accomplish this loop, but it currently is not working and when I try and run it, it is giving me an error saying "Object Required" and highlighting "(NumberOfApptsTextBox)" in the line that reads "Set apptsToSet = (NumberOfApptsTextBox) . I thought the NumberOfApptsTextBox was the object!

Code:
Private Sub EnterButton_Click()


            Dim thisSheet As Worksheet
            Dim stopDate As Date
            Dim thisAppointment As Date
            Dim apptsToSet As Integer
            
            Set thisSheet = thisWorkbook.Sheets("Future Appointments")
                    If SchoolNameComboBox = "" Or ApptDateTextBox = "" Or ApptTimeTextBox = "" Or SchedStatusComboBox = "" Or WeeklyIntervalTextBox = "" Then
                        MsgBox "All of These Fields are REQUIRED..." & _
                            vbNewLine & _
                            "          - SCHOOL NAME" & vbNewLine & _
                            "          - APPOINTMENT DATE" & vbNewLine & _
                            "          - APPOINTMENT TIME" & vbNewLine & _
                            "          - STATUS TO SET" & vbNewLine & _
                            "          - AT ____ WEEK INTERVALS" & vbNewLine & vbNewLine & _
                            "At Least 1 of These 2 Fields are REQUIRED..." & vbNewLine & _
                            "          - SET ____ APPOINTMENTS" & vbNewLine & _
                            "          - STOP DATE" & vbNewLine & vbNewLine & _
                            "This Field is OPTIONAL..." & vbNewLine & _
                            "          - DEFAULT NOTE", vbOKOnly, "INCOMPLETE INFORMATION"
                    Else
    '                    Set apptsToSet = NumberOfApptsTextBox
    '                    Set stopDate = CDate(Me.StopDateTextBox)
                            Do
                        
Set apptsToSet = (NumberOfApptsTextBox)
NextAppDate = IIf(MaxDate = 0, "", MaxDate)
    If NumberOfApptsTextBox <> "" Then
        Call NumberOfApptsTextBox_Change
            If NumberOfApptsTextBox = 0 Then
                End Sub
            End If
    End If
'                            Set thisAppointment = CDate(Me.ApptDateTextBox)
                                If Not WeeklyIntervalTextBox = "" And thisAppointment <= stopDate Then
                                       NextAppDate = DateAdd("w", CDbl(WeeklyIntervalTextBox * 7), ApptDateTextBox)
                                Else
                                    ThisName = SchoolNameComboBox
                                        With Worksheets("Future Appointments")
                                            SchoolNames = Intersect(.Range("A2").CurrentRegion, .Range("A:A"))
                                            SchoolDays = Intersect(.Range("A2").CurrentRegion, .Range("G:G"))  'Edit to fit
                                        End With
                                    
                                        For i = LBound(SchoolNames) + 1 To UBound(SchoolNames) '+1 to skip headers
                                           If SchoolNames(i, 1) = ThisName Then MaxDate = Application.Max(MaxDate, SchoolDays(i, 1))
                                        Next i
                                    NextAppDate = IIf(MaxDate = 0, "", MaxDate)
                                End If
                                    ApptDateTextBox.Text = NextAppDate
                                nextrow = thisSheet.Cells(Rows.Count, 1).End(xlUp).Row + 1
                                        If NumberOfApptsTextBox <> 0 Then
                                            thisSheet.Cells(nextrow, 1) = Me.SchoolNameComboBox
                                            thisSheet.Cells(nextrow, 5) = Me.SchedStatusComboBox
                                            thisSheet.Cells(nextrow, 7) = CDate(Me.ApptDateTextBox)
                                            thisSheet.Cells(nextrow, 8) = CDate(Me.ApptTimeTextBox)
                                            thisSheet.Cells(nextrow, 9) = Me.DefaultNoteTextBox
                                        End If
                            Loop While NumberOfApptsTextBox <> 0
                                    End If
                        Me.Hide
                            Unload Me


End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
I don't understand why you want to set the object "NumberOfApptsTextBox" to another object "apptsToSet".
Simply use the textbox "NumberOfApptsTextBox"

Or try this

You must change the statement:
you have:
Code:
Dim apptsToSet As Integer


must be:

Code:
Dim apptsToSet As Object

And:
Code:
Set apptsToSet = NumberOfApptsTextBox

-------------
 
Upvote 0
I really appreciate the quick reply... I got tied up and just got to where I could try this and respond. I have corrected the above and honestly I am not sure about Objects, this is pretty new to me.

You must change the statement:
you have:
Code:
Dim apptsToSet As Integer


must be:

Code:
Dim apptsToSet As Object

And:
Code:
Set apptsToSet = NumberOfApptsTextBox

-------------


I am trying to stumble my way through this because this is my first attempt at using InputBox to run code using Loops. What I am trying to do is run this code until the 1st of 2 different conditions are met from the InputBox. I have several TextBoxes on the InputBox but 3 in particular are going to be used in this code. The first two TextBoxes is called "NumberOfApptsTextBox", this is where the user will enter a number. The second TextBox is called "StopDateTextBox", this is where the user will enter a future date. At least 1 of these 2 TextBoxes are required to continue running the code, if at least one of them is not filled in it should put up the message box at the top of the code. The 3rd TextBox is called "WeeklyIntervalTextBox" where the user will enter a number, this represents the number of weeks in between each appointment to set appointments at on the workbook, this is also is also a required field on the InputBox. Again the part that is indented is working fine as long as I step through the code, the part that is left justified is what I have added in an attempt to loop.

The code enters future appointments from the Input Box using "WeeklyIntervalTextBox" to tell it how frequently to set appointments at. This part is working as long as I step through the code. If I dont step through it will get locked into an infinite loop. This is where at least one of the other two TextBoxes come in. There are 3 possible scenarios...

1. If there is a value in "NumberOfApptsTextBox" and no value in "StopDateTextBox" the code will enter that number of appointments and stop once it has looped that many times.

2. If there is no value in "NumberOfApptsTextBox" but there is a value in "StopDateTextBox" then it will enter appointments at the user defined weekly interval from "WeeklyIntervalTextBox" until the next appointment date would exceed the date in "StopDateTextBox" and stop there.

3. If there is a value in both "NumberOfApptsTextBox" and "StopDateTextBox" then it will enter appointments at the user defined weekly interval until the first condition of either "NumberOfApptsTextBox" or "StopDateTextBox" is met and stop there.

Code:
Private Sub EnterButton_Click()


            Dim thisSheet As Worksheet
            Dim stopDate As Date
            Dim thisAppointment As Date
            Dim apptsToSet As Object


            Set thisSheet = thisWorkbook.Sheets("Future Appointments")
                    If SchoolNameComboBox = "" Or ApptDateTextBox = "" Or ApptTimeTextBox = "" Or SchedStatusComboBox = "" Or WeeklyIntervalTextBox = "" And (NumberOfApptsTextBox <> "" Or StopDateTextBox <> "") Then
                        MsgBox "All of These Fields are REQUIRED..." & _
                            vbNewLine & _
                            "          - SCHOOL NAME" & vbNewLine & _
                            "          - APPOINTMENT DATE" & vbNewLine & _
                            "          - APPOINTMENT TIME" & vbNewLine & _
                            "          - STATUS TO SET" & vbNewLine & _
                            "          - AT ____ WEEK INTERVALS" & vbNewLine & vbNewLine & _
                            "At Least 1 of These 2 Fields are REQUIRED..." & vbNewLine & _
                            "          - SET ____ APPOINTMENTS" & vbNewLine & _
                            "          - STOP DATE" & vbNewLine & vbNewLine & _
                            "This Field is OPTIONAL..." & vbNewLine & _
                            "          - DEFAULT NOTE", vbOKOnly, "INCOMPLETE INFORMATION"
                    Else
    '                    Set apptsToSet = NumberOfApptsTextBox
    '                    Set stopDate = CDate(Me.StopDateTextBox)
                        
Set apptsToSet = NumberOfApptsTextBox
NextAppDate = IIf(MaxDate = 0, "", MaxDate)
    If NumberOfApptsTextBox <> "" Then
        Call NumberOfApptsTextBox_Change
            If NumberOfApptsTextBox = 0 Then
                End Sub
            End If
        Do
            If Not WeeklyIntervalTextBox = "" And thisAppointment <= stopDate Then
                   NextAppDate = DateAdd("w", CDbl(WeeklyIntervalTextBox * 7), ApptDateTextBox)
            Else
                ThisName = SchoolNameComboBox
                    With Worksheets("Future Appointments")
                        SchoolNames = Intersect(.Range("A2").CurrentRegion, .Range("A:A"))
                        SchoolDays = Intersect(.Range("A2").CurrentRegion, .Range("G:G"))  'Edit to fit
                    End With
                
                    For i = LBound(SchoolNames) + 1 To UBound(SchoolNames) '+1 to skip headers
                       If SchoolNames(i, 1) = ThisName Then MaxDate = Application.Max(MaxDate, SchoolDays(i, 1))
                    Next i
                NextAppDate = IIf(MaxDate = 0, "", MaxDate)
            End If
                ApptDateTextBox.Text = NextAppDate
            nextrow = thisSheet.Cells(Rows.Count, 1).End(xlUp).Row + 1
                    If NumberOfApptsTextBox <> 0 Then
                        thisSheet.Cells(nextrow, 1) = Me.SchoolNameComboBox
                        thisSheet.Cells(nextrow, 5) = Me.SchedStatusComboBox
                        thisSheet.Cells(nextrow, 7) = CDate(Me.ApptDateTextBox)
                        thisSheet.Cells(nextrow, 8) = CDate(Me.ApptTimeTextBox)
                        thisSheet.Cells(nextrow, 9) = Me.DefaultNoteTextBox
                    End If
                        NumberOfApptsTextBox -1
        Loop While NumberOfApptsTextBox <> 0
'                End If
'            End If
    End If
'                            Set thisAppointment = CDate(Me.ApptDateTextBox)
                            Do
                                If Not WeeklyIntervalTextBox = "" And NumberOfApptsTextBox <> 0 And thisAppointment <= stopDate Then
                                       NextAppDate = DateAdd("w", CDbl(WeeklyIntervalTextBox * 7), ApptDateTextBox)
                                Else
                                    ThisName = SchoolNameComboBox
                                        With Worksheets("Future Appointments")
                                            SchoolNames = Intersect(.Range("A2").CurrentRegion, .Range("A:A"))
                                            SchoolDays = Intersect(.Range("A2").CurrentRegion, .Range("G:G"))  'Edit to fit
                                        End With
                                    
                                        For i = LBound(SchoolNames) + 1 To UBound(SchoolNames) '+1 to skip headers
                                           If SchoolNames(i, 1) = ThisName Then MaxDate = Application.Max(MaxDate, SchoolDays(i, 1))
                                        Next i
                                    NextAppDate = IIf(MaxDate = 0, "", MaxDate)
                                End If
                                    ApptDateTextBox.Text = NextAppDate
                                nextrow = thisSheet.Cells(Rows.Count, 1).End(xlUp).Row + 1
                                        If NumberOfApptsTextBox <> 0 Then
                                            thisSheet.Cells(nextrow, 1) = Me.SchoolNameComboBox
                                            thisSheet.Cells(nextrow, 5) = Me.SchedStatusComboBox
                                            thisSheet.Cells(nextrow, 7) = CDate(Me.ApptDateTextBox)
                                            thisSheet.Cells(nextrow, 8) = CDate(Me.ApptTimeTextBox)
                                            thisSheet.Cells(nextrow, 9) = Me.DefaultNoteTextBox
                                        End If
                            Loop While NumberOfApptsTextBox <> 0
                                End If
                        Me.Hide
                            Unload Me


End Sub
 
Upvote 0
You had a problem in the declaration of the variable.
But now I don't understand what the problem is.
Do you want help with all the code?
You must explain step by step, in great detail and examples what you want to do.
 
Upvote 0
Thank you DanteAmor,

I actually have figured out most of this but since my last response. The response took a while to get to you because I am a new member to Mr. Excel and it got sent to an administrator for review before posting. I am pasting all of the code for the UserForm below in it's entirety. The section I am currently having problems with is the part between the " '/////////////// " in "Private Sub EnterButton_Click()". The section above this marking is working. I am copying the explanation from below with a bit more clarification. Hopefully with the entire UserForm event code and the added explanation it will make more sense. If not please let me know. You asked for "step by step in great detail" so here it is...

You had a problem in the declaration of the variable.
But now I don't understand what the problem is.
Do you want help with all the code?
You must explain step by step, in great detail and examples what you want to do.

The code enters future appointments from the Input Box using "WeeklyIntervalTextBox" to tell it how frequently to set appointments at. This part is working as long as I step through the code. If I dont step through it will get locked into an infinite loop. This is where at least one of the other two TextBoxes come in. There are 3 possible scenarios...

1. If there is a value in "NumberOfApptsTextBox" and no value in "StopDateTextBox" the code will enter that number of appointments and stop once it has looped that many times.

-- This part is working fine

2. If there is no value in "NumberOfApptsTextBox" but there is a value in "StopDateTextBox" then it will enter appointments at the user defined weekly interval from "WeeklyIntervalTextBox" until the next appointment date would exceed the date in "StopDateTextBox" and stop there.

-- This part is mostly working in that it does enter the appointments at the correct weekly interval except

--------- 1. It does not stop when the date that is entered in "StopDateTextBox" would be exceeded, it just continues to enter appointments on the worksheet, which causes an infinite loop. When I step through the code I can see the value in the variable "stopDate" but it is wrapped in quotes but when I look at the variable "NextAppDate" it does not show it wrapped on quotes. I "think" this may be the issue but I really am not sure, and I have gone through it to see if I missed anything and I cannot find it.

--------- 2. When the UserForm is pulled up and a school is selected from "SchoolNameComboBox", if there is already a future appointment on that sheet, it is supposed to put that "MaxDate" in the "ApptDateTextBox" and when the Enter Button is pressed, it should set the next appointment for the date that is in "ApptDateTextBox" PLUS the number of weeks that is in "WeeklyIntervalTextBox"

EXAMPLE ----- if there is "ABC School" in "SchoolNameTextBox" and there is already an appointment set for 12/1/2019, it should place that date in "ApptDateTextBox" on the UserForm (this part is working). In this case, if there is a "6" entered in "WeeklyIntervalTextBox" and there is a date of "12/31/2020" entered in "StopDateTextBox", when the enter button is pressed, it should set the next appointment for 1/12/2020 (which would be 6 weeks after 12/1/2019) and continue to enter appointments at 6 week intervals until the next appointment to be set would exceed "12/31/2020" that is entered in "StopDateTextBox", if the next appointment would go past that date it should stop.

What the code is currently doing in this case is if there is already an appointment set for 12/1/2019 and there is a "6" in "WeeklyIntervalTextBox" instead of setting the next appointment for 1/12/2020, it sets the first appointment for 12/1/2019 (which causes a duplicate appointment) then continues to set appointments at 6 weeks apart but gets caught in the infinite loop because it also is not recognizing the date that is entered in the "StopDateTextBox".

If there currently is no appointment set on the sheet yet then "ApptDateTextBox" would be blank and the user can enter the date they want the first appointment to be set for. So using the same case, the user would enter a date of "12/1/2019" in the "ApptDateTextBox" and enter "6" in "WeeklyIntervalTextBox" and when they press the Enter Button, it do the same thing except it should stop at the date entered in "StopDateTextBox" and it doesn't

3. If there is a value in both "NumberOfApptsTextBox" and "StopDateTextBox" then it will enter appointments at the user defined weekly interval until the first condition of either "NumberOfApptsTextBox" or "StopDateTextBox" is met and stop there.

-- This part is going to be a combination of the above to scenarios but it is going to stop when EITHER the number entered in "NumberOfApptsTextBox" is met OR the next appointment to be set would exceed the date entered in "StopDateTextBox", which ever condition is met first. I think this is just going to be cobbling of the above two with a "if "condition" or "condition" Then" statement. I do have the vast majority of this working but the infinite loop thing is driving me nuts. :oops:


Code:
Private Sub SchoolNameComboBox_Change()


        Dim SchoolNames  As Variant
        Dim SchoolDays As Variant
        Dim i As Long
        Dim MaxDate As Date
        Dim ThisName As String
        Dim NextAppDate As Date
        Dim weeks As Double
        
            Sheets("Future Appointments").Select
                ActiveSheet.Unprotect Password:="KingJesus1996"
                    ThisName = SchoolNameComboBox
                        With Worksheets("Future Appointments")
                            SchoolNames = Intersect(.Range("A2").CurrentRegion, .Range("A:A"))
                            SchoolDays = Intersect(.Range("A2").CurrentRegion, .Range("G:G"))  'Edit to fit
                        End With
                    
                        For i = LBound(SchoolNames) + 1 To UBound(SchoolNames) '+1 to skip headers
                           If SchoolNames(i, 1) = ThisName Then MaxDate = Application.Max(MaxDate, SchoolDays(i, 1))
                        Next i
                            If MaxDate = 0 Then Exit Sub
                NextAppDate = IIf(MaxDate = 0, "", MaxDate)
'                   If Not WeeklyIntervalTextBox = "" Then
'                         NextAppDate = DateAdd("ww", CDbl(WeeklyIntervalTextBox), NextAppDate)
'                   End If
                ApptDateTextBox.Text = NextAppDate


End Sub


Private Sub ApptDateTextBox_Change()




End Sub


Private Sub ApptTimeTextBox_Change()


End Sub


Private Sub ComboBox1_Change()


End Sub


Private Sub SchedStatusComboBox_Change()


End Sub


Private Sub DefaultNoteTextBox_Change()


End Sub


Private Sub NumberOfApptsTextBox_Change()


End Sub


Private Sub WeeklyIntervalTextBox_Change()


            Dim NextAppDate As Date
    
                If Not WeeklyIntervalTextBox = "" Then
                       NextAppDate = ApptDateTextBox
                Else
                    ThisName = SchoolNameComboBox
                        With Worksheets("Future Appointments")
                            SchoolNames = Intersect(.Range("A2").CurrentRegion, .Range("A:A"))
                            SchoolDays = Intersect(.Range("A2").CurrentRegion, .Range("G:G"))  'Edit to fit
                        End With
                    
                        For i = LBound(SchoolNames) + 1 To UBound(SchoolNames) '+1 to skip headers
                           If SchoolNames(i, 1) = ThisName Then MaxDate = Application.Max(MaxDate, SchoolDays(i, 1))
                        Next i
                        
    
                End If
    
            ApptDateTextBox.Text = NextAppDate


End Sub


Private Sub StopDateTextBox_Change()




End Sub


Private Sub EnterButton_Click()


            Dim thisSheet As Worksheet
            Dim thisAppointment As Object
            Dim apptsToSet As Object
            Dim schoolName As Range
            Dim stopDate As Object


'        Application.ScreenUpdating = False
            Set thisSheet = thisWorkbook.Sheets("Future Appointments")
                    If SchoolNameComboBox = "" Or ApptDateTextBox = "" Or ApptTimeTextBox = "" Or SchedStatusComboBox = "" Or WeeklyIntervalTextBox = "" Then
                        MsgBox "All of These Fields are REQUIRED..." & _
                            vbNewLine & _
                            "          - SCHOOL NAME" & vbNewLine & _
                            "          - APPOINTMENT DATE" & vbNewLine & _
                            "          - APPOINTMENT TIME" & vbNewLine & _
                            "          - STATUS TO SET" & vbNewLine & _
                            "          - AT ____ WEEK INTERVALS" & vbNewLine & vbNewLine & _
                            "This Field is OPTIONAL..." & vbNewLine & _
                            "          - DEFAULT NOTE", vbOKOnly, "INCOMPLETE INFORMATION"
                    Else
                        If NumberOfApptsTextBox = "" And StopDateTextBox = "" Then
                            MsgBox "You Must Enter the Number of Appointments You" & vbNewLine & _
                                    "Would Like To Set or a Stop Date to Proceed.", vbOKCancel, "INCOMPLETE INFORMATION"
                                        
                                        
                                        If vbOK Then Exit Sub
    '                                    End If
            
                        Else
                            If NumberOfApptsTextBox <> "" And StopDateTextBox = "" Then
                                Set apptsToSet = NumberOfApptsTextBox
'Set NextAppDate = ApptDateTextBox
                                NextAppDate = IIf(MaxDate = 0, "", NextAppDate)
                                    If NumberOfApptsTextBox <> "" Or NumberOfApptsTextBox <> 0 Then
                                        Call NumberOfApptsTextBox_Change
                                            If NumberOfApptsTextBox = 0 Then Exit Sub
                                '            End If
                                        Do
                                            If Not WeeklyIntervalTextBox = "" Then
                                                   NextAppDate = DateAdd("w", CDbl(WeeklyIntervalTextBox * 7), ApptDateTextBox)
                                            Else
                                                ThisName = SchoolNameComboBox
                                                    With Worksheets("Future Appointments")
                                                        SchoolNames = Intersect(.Range("A2").CurrentRegion, .Range("A:A"))
                                                        SchoolDays = Intersect(.Range("A2").CurrentRegion, .Range("G:G"))  'Edit to fit
                                                    End With
                                                
                                                    For i = LBound(SchoolNames) + 1 To UBound(SchoolNames) '+1 to skip headers
                                                       If SchoolNames(i, 1) = ThisName Then MaxDate = Application.Max(MaxDate, SchoolDays(i, 1))
                                                    Next i
                                                NextAppDate = IIf(MaxDate = 0, "", MaxDate)
                                            End If
                                            nextrow = thisSheet.Cells(Rows.Count, 1).End(xlUp).Row + 1
                                                    If NumberOfApptsTextBox <> 0 Then
                                                        thisSheet.Cells(nextrow, 1) = Me.SchoolNameComboBox
                                                        thisSheet.Cells(nextrow, 5) = Me.SchedStatusComboBox
                                                        thisSheet.Cells(nextrow, 7) = CDate(Me.ApptDateTextBox)
                                                        thisSheet.Cells(nextrow, 8) = CDate(Me.ApptTimeTextBox)
                                                        thisSheet.Cells(nextrow, 9) = Me.DefaultNoteTextBox
                                                    End If
                                                        ApptDateTextBox.Text = NextAppDate
                                                        apptsToSet = NumberOfApptsTextBox - 1
                                        Loop While NumberOfApptsTextBox <> 0
                                    End If
                                        Me.Hide
                                            Unload Me
                                                Exit Sub
'                        End If


'///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


                        Else
                            If NumberOfApptsTextBox = "" And StopDateTextBox <> "" Then
                                Set stopDate = StopDateTextBox
                                Set thisAppointment = WeeklyIntervalTextBox
                                    NextAppDate = IIf(MaxDate = 0, "", MaxDate)
                                        If MaxDate + nextApptDate <= stopDate Then
                                        Call NumberOfApptsTextBox_Change
                                            If NumberOfApptsTextBox = 0 Then Exit Sub
                                '            End If
                                        Do
                                            If NextAppDate <= StopDateTextBox Then
                                                   NextAppDate = DateAdd("w", CDbl(WeeklyIntervalTextBox * 7), ApptDateTextBox)
                                                   stopDate = Date
                                            Else
                                                ThisName = SchoolNameComboBox
                                                    With Worksheets("Future Appointments")
                                                        SchoolNames = Intersect(.Range("A2").CurrentRegion, .Range("A:A"))
                                                        SchoolDays = Intersect(.Range("A2").CurrentRegion, .Range("G:G"))  'Edit to fit
                                                    End With
                                                
                                                    For i = LBound(SchoolNames) + 1 To UBound(SchoolNames) '+1 to skip headers
                                                       If SchoolNames(i, 1) = ThisName Then MaxDate = Application.Max(MaxDate, SchoolDays(i, 1))
                                                    Next i
                                                NextAppDate = IIf(MaxDate = 0, "", MaxDate)
                                            End If
                                            nextrow = thisSheet.Cells(Rows.Count, 1).End(xlUp).Row + 1
                                                    If NumberOfApptsTextBox <> 0 Then
                                                        thisSheet.Cells(nextrow, 1) = Me.SchoolNameComboBox
                                                        thisSheet.Cells(nextrow, 5) = Me.SchedStatusComboBox
                                                        thisSheet.Cells(nextrow, 7) = CDate(Me.ApptDateTextBox)
                                                        thisSheet.Cells(nextrow, 8) = CDate(Me.ApptTimeTextBox)
                                                        thisSheet.Cells(nextrow, 9) = Me.DefaultNoteTextBox
                                                    End If
                                                        ApptDateTextBox.Text = NextAppDate
                                                        StopDateTextBox.Text = stopDate
                                        Loop While NextAppDate <= stopDate
                                    End If
                                        Me.Hide
                                            Unload Me
                                                Exit Sub
                                                
'///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                
                            End If
                            End If
''                                End If
''                            End If
                        End If
                    End If
                    
                        If vbCancel Then
                            Me.Hide
                                Unload Me
                        End If


End Sub


Private Sub CancelButton_Click()


            ActiveWorkbook.Protect Password:="KingJesus1996", Structure:=True, Windows:=False
                ActiveSheet.AutoFilter.ShowAllData
                    Me.Hide
                    Unload Me


End Sub


Private Sub UserForm_Initialize()
        Dim schoolName As Range
        Dim schedStatus As Range
        Dim ws As Worksheet
            
            Me.Top = Application.Top + (Application.UsableHeight / 2) - (Me.Height / 2)
            Me.Left = Application.Left + (Application.UsableWidth / 2) - (Me.Width / 2)
                Set ws = Worksheets("Data Sheet")
                    For Each schoolName In ws.Range("School_Names")
                        With Me.SchoolNameComboBox
                            .AddItem schoolName.Value
                        End With
                    Next schoolName
                    For Each schedStatus In ws.Range("Sched_Status")
                        With Me.SchedStatusComboBox
                            .AddItem schedStatus.Value
                        End With
                    Next schedStatus
                
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,332
Members
449,077
Latest member
jmsotelo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top