Eric Carolus
Board Regular
- Joined
- Sep 17, 2012
- Messages
- 133
- Office Version
- 2016
- Platform
- Windows
Hi folks
''This this the code for the worksheet called Teachers
I have a workbook with two sheets only, one called Teachers and the other called Uneven N Days.
On the sheet called Teachers, I have a dynamic range of teacher names. If I simply select a teacher name (A CELL), the user will be warned that that particular teacher may be deleted BUT
then the user have the choice to delete the teacher or not.
Should the user wish to delete the teacher, the teacher will then be removed (from the list of teacher names).
At the same time THAT teacher's name will be saved in a variable called NamesXX.
When you activate the sheet called Uneven N Days, a Msgbox will show the DELETED teacher that had been deleted from the sheet called Teachers.
That teacher will the be deleted from the sheet called Uneven N Days, WITH the number next to that teacher.
My problem: I want the same to happen when I SELECT THE ROW NUMBER ON THE SHEET CALLED "Teachers".
Its a matter of selecting a cell vs selecting a row number on the sheet called "Teachers"
I can use all help.
I thank you in advance.
Crow
''This this the code for the worksheet called Teachers
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error Resume Next
If Target.Row >= 1 And Target.Row <= 2 Then
MsgBox "You Cannot Delete the Header,called 'Teachers', OK?" _
& vbCrLf _
& vbCrLf _
& "You are restricted from doing so!" _
& vbCrLf _
& vbCrLf _
& ".................................................." _
& vbCrLf _
& vbCrLf _
& " Thanks" _
& vbCrLf _
& vbCrLf _
& vbCrLf _
& vbCrLf _
& " Author: [EMAIL]solutions.crow@gmail.com[/EMAIL]", vbInformation, " Restricted from Deletion"
'MsgBox "Check"
ActiveSheet.Protect Password:="CROW-RA1ND-RO2BY-AR3LE-RENN", DrawingObjects:=True, contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowInsertingRows:=False, AllowDeletingRows:=False
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Else
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Selection.EntireRow.Select
''1. WORKED LIKE A CHARM!!
NamesXX = Intersect(ActiveCell, Range("C3:C100")).Value
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'2. WORKED LIKE A CHARM!!
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'NamesXX = Intersect(ActiveCell, Range("Teachers")).Value
If NamesXX = "" Then
Exit Sub
Else
Dim answer As String
'Request from user if he/she wish to remove the teacher
answer = MsgBox("You want to remove teacher" & "' " & NamesXX & "' " & "?" _
& vbCrLf _
& vbCrLf _
& "Remember, you are about to remove this" _
& vbCrLf _
& vbCrLf _
& "teacher permanently from the teacher list!" _
& vbCrLf _
& vbCrLf _
& "........................................................................" _
& vbCrLf _
& vbCrLf _
& "In ADDITION,the teacher will also be" _
& vbCrLf _
& vbCrLf _
& "removed from the allocation!", vbCritical + vbOKCancel, " Permanent removal of teacher!")
'Display the name of the chosen teacher
MsgBox NamesXX
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If answer = vbOK Then
'Remove the name of the teacher from the list of teachers
Intersect(ActiveCell, Range("C3:C100")).ClearContents
MsgBox NamesXX
'Do not remove the teacher if the user Cancel the action
ElseIf answer = vbCancel Then
' Exit Sub
MsgBox " You chose not to remove the teacher!"
NamesXX = ""
End If
End If
ActiveSheet.Unprotect Password:="CROW-RA1ND-RO2BY-AR3LE-RENN"
End If
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
End Sub
''
''This is the worksheet called Uneven N Days
Private Sub Worksheet_Activate()
MsgBox NamesXX
Dim TeacherNames As Range
Dim cell As Range
''
Set TeacherNames = Worksheets("Uneven N Days").Range("C5:AV35")
If NamesXX = "" Then
Exit Sub
Else
For Each cell In TeacherNames
If cell.Value = NamesXX Then
cell.ClearContents
cell.Offset(0, 1).ClearContents
End If
Next
End If
End Sub
I have a workbook with two sheets only, one called Teachers and the other called Uneven N Days.
On the sheet called Teachers, I have a dynamic range of teacher names. If I simply select a teacher name (A CELL), the user will be warned that that particular teacher may be deleted BUT
then the user have the choice to delete the teacher or not.
Should the user wish to delete the teacher, the teacher will then be removed (from the list of teacher names).
At the same time THAT teacher's name will be saved in a variable called NamesXX.
When you activate the sheet called Uneven N Days, a Msgbox will show the DELETED teacher that had been deleted from the sheet called Teachers.
That teacher will the be deleted from the sheet called Uneven N Days, WITH the number next to that teacher.
My problem: I want the same to happen when I SELECT THE ROW NUMBER ON THE SHEET CALLED "Teachers".
Its a matter of selecting a cell vs selecting a row number on the sheet called "Teachers"
I can use all help.
I thank you in advance.
Crow
Last edited by a moderator: