steve.waye
Board Regular
- Joined
- Jul 8, 2010
- Messages
- 68
Hi,
I'm relatively new to VBA so any help would be appreciated.
I have an Excel Workbook that I use to allocate staff to classes in our teaching section. My workbook has two sheets - 'Staff' and 'Program'.
The 'Staff' worksheet lists all staff, including their initials (e.g. SW).
The 'Program' worksheet has the teaching program with an adjacent space to enter the teacher's initials.
When I enter the staff member's initials on the 'Program' sheet, this cell and the adjacent two cells are highlighted a specific colour for that staff member.
I am currently using VBA to do this which works well. However, if I have a change of staff, I need to go into the VBA code to edit it to suit the new initials. This isn't a problem for me, but there are several other Head Teachers who want to use the Workbook for their own teaching sections and find the whole VBA thing a bit daunting. As such I want to password protect the code against access (and destruction).
I was hoping there was some way to declare the teacher initials on the 'Staff' sheet as variables which could then be used in the code in Module1.
Here's the code in Module1...
<CODE>Sub HighlightTextByTeacher(ByVal TeacherInitials As Range, ByVal CellToHighlight As Range)
Dim icolor As Integer
If ((Not Intersect(TeacherInitials, Range("E4:E57")) Is Nothing) Or (Not Intersect(TeacherInitials, Range("H4:H57")) Is Nothing) Or (Not Intersect(TeacherInitials, Range("K4:K57")) Is Nothing)) Then
Select Case UCase(TeacherInitials.Value)
Case ""
icolor = -1
Case "SW"
icolor = 22
Case "AN"
icolor = 24
Case "SJ"
icolor = 26
Case "FG"
icolor = 27
Case "PH"
icolor = 28
Case Else
MsgBox ("Invalid teacher initials '" & TeacherInitials.Value & "' detected.")
End Select
CellToHighlight.Interior.ColorIndex = icolor
End If
End Sub
I can supply a copy of the Workbook if that helps, but not sure of the protocol.
Regards, Steve
</CODE>
I'm relatively new to VBA so any help would be appreciated.
I have an Excel Workbook that I use to allocate staff to classes in our teaching section. My workbook has two sheets - 'Staff' and 'Program'.
The 'Staff' worksheet lists all staff, including their initials (e.g. SW).
The 'Program' worksheet has the teaching program with an adjacent space to enter the teacher's initials.
When I enter the staff member's initials on the 'Program' sheet, this cell and the adjacent two cells are highlighted a specific colour for that staff member.
I am currently using VBA to do this which works well. However, if I have a change of staff, I need to go into the VBA code to edit it to suit the new initials. This isn't a problem for me, but there are several other Head Teachers who want to use the Workbook for their own teaching sections and find the whole VBA thing a bit daunting. As such I want to password protect the code against access (and destruction).
I was hoping there was some way to declare the teacher initials on the 'Staff' sheet as variables which could then be used in the code in Module1.
Here's the code in Module1...
<CODE>Sub HighlightTextByTeacher(ByVal TeacherInitials As Range, ByVal CellToHighlight As Range)
Dim icolor As Integer
If ((Not Intersect(TeacherInitials, Range("E4:E57")) Is Nothing) Or (Not Intersect(TeacherInitials, Range("H4:H57")) Is Nothing) Or (Not Intersect(TeacherInitials, Range("K4:K57")) Is Nothing)) Then
Select Case UCase(TeacherInitials.Value)
Case ""
icolor = -1
Case "SW"
icolor = 22
Case "AN"
icolor = 24
Case "SJ"
icolor = 26
Case "FG"
icolor = 27
Case "PH"
icolor = 28
Case Else
MsgBox ("Invalid teacher initials '" & TeacherInitials.Value & "' detected.")
End Select
CellToHighlight.Interior.ColorIndex = icolor
End If
End Sub
I can supply a copy of the Workbook if that helps, but not sure of the protocol.
Regards, Steve
</CODE>
Last edited: