Private Sub Enroll() Dim code As Long code = TextBox1.Value If 108000000 < code
ID: 3709539 • Letter: P
Question
Private Sub Enroll()
Dim code As Long
code = TextBox1.Value
If 108000000 < code And code < 120000000 Then
If TextBox2 = "Welcome" Then
MsgBox "Welcome."
MsgBox "Enroll the classes."
Sheet1.Activate
Else:
MsgBox "The password is wrong."
MsgBox "Exit the log-in."
End If
Unload Me
Else
TextBox1.Text = ""
MsgBox "Please write the id number again."
End If
Columns("A:E").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Rows("1:12").Select
Selection.Delete Shift:=xlUp
Columns("K:K").Select
Selection.Delete Shift:=xlToLeft
Range("J1").Select
ActiveCell.FormulaR1C1 = "course name"
ActiveSheet.Range("a1").CurrentRegion.Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.FormulaR1C1 = "=R[-1]C"
ActiveSheet.Range("a1").CurrentRegion.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Range("I1").Select
Application.CutCopyMode = False
Selection.AutoFilter
ActiveSheet.Range("a1").CurrentRegion.AutoFilter Field:=9, Criteria1:="Total"
Rows("2:2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
ActiveSheet.Range("a1").CurrentRegion.AutoFilter Field:=9
Columns("F:I").Select
Range("I1").Activate
Selection.Delete Shift:=xlToLeft
End Sub
This is VBA in Excel code. However there is some error.. please help me to fix it.
something like
compile error: invalid Me keyword.
Explanation / Answer
Try this piece of Code to handle "Unload Me"
In doing so, it will not attempt to unload a control, but rather will unload the user form where the button control resides. The "Me" keyword refers to the user form object even when called from a control on the user form.
So remove "Unload Me" from Sub Enroll() and create a Sub procedure on the the close of the form which can handle "Unload Me" as shown in the Sub btnClose_Click()
Please let me know in case of any clarifications required. Thanks!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.