VBA code in excel to work for many sheets
Closed
issa
-
Feb 2, 2012 at 01:17 PM
aquarelle Posts 5959 Registration date Saturday April 7, 2007 Status Moderator Last seen February 9, 2026 - Feb 2, 2012 at 03:27 PM
aquarelle Posts 5959 Registration date Saturday April 7, 2007 Status Moderator Last seen February 9, 2026 - Feb 2, 2012 at 03:27 PM
Related:
- VBA code in excel to work for many sheets
- Excel online vba - Guide
- Vba excel mac - Guide
- Excel mod apk for pc - Download - Spreadsheets
- Number to words in excel formula without vba - Guide
- Google sheets right to left - Guide
1 response
aquarelle
Posts
5959
Registration date
Saturday April 7, 2007
Status
Moderator
Last seen
February 9, 2026
491
Feb 2, 2012 at 03:27 PM
Feb 2, 2012 at 03:27 PM
Hi,
I think it is not necessary to write your code for each worksheet and I think that you should just try to write your code in "ThisWorkbook" like this :
Regards
I think it is not necessary to write your code for each worksheet and I think that you should just try to write your code in "ThisWorkbook" like this :
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Const PW As String = "issa2011"
Dim cRow As Integer
If Intersect(Target, Range("AQ12:AQ47")) Is Nothing Then Exit Sub
If Target.Value = "DTIME" Or Target.Value = "DTOME" Then
ActiveSheet.Unprotect PW
cRow = Target.Row
Range(Cells(cRow, "AR"), Cells(cRow, "AS")).Locked = True
ActiveSheet.Protect PW
Else
If Target.Value = "DTIME" And Target.Value <> "" Then
MsgBox "Please Note: there no need to fill time and thank you.", vbExclamation, Title:="Human Resource Office Warning"
End If
End If
If Target.Value <> "DTIME" Or Target.Value <> "DTOME" Then
ActiveSheet.Unprotect PW
cRow = Target.Row
Range(Cells(cRow, "AR"), Cells(cRow, "AS")).Locked = False
ActiveSheet.Protect PW
End If
End Sub
Regards