showarv2020
New Member
- Joined
- Nov 7, 2022
- Messages
- 3
- Office Version
- 2019
- Platform
- Windows
Option Explicit
Sub Update_Current_Time()
Dim sh As Worksheet
Set sh = ActiveSheet
'''' Validations''''''''''
Dim rng As Range
Set rng = Selection
If Application.WorksheetFunction.CountBlank(rng) <> 1 Then
MsgBox "Incorrect range selection", vbCritical
Exit Sub
End If
If rng.Row < 5 Or rng.Row > 35 Then
MsgBox "Incorrect range selection", vbCritical
Exit Sub
End If
If rng.Column < 2 Or rng.Column > 30 Then
MsgBox "Incorrect range selection", vbCritical
Exit Sub
End If
If sh.Cells(rng.Row, 1).Value <> Int(Now) Then
MsgBox "You can update the time for today only", vbCritical
Exit Sub
End If
'''''''''''''''''''''
sh.Unprotect "1234"
rng.Value = Now
sh.Protect "1234"
End Sub
Sub Clear_sheet()
Dim sh As Worksheet
Set sh = ActiveSheet
sh.Unprotect "1234"
sh.Range("B5:G35").ClearContents
sh.Protect "1234"
End Sub
the underline VBA code are not working when i put my date in horizontally
Sub Update_Current_Time()
Dim sh As Worksheet
Set sh = ActiveSheet
'''' Validations''''''''''
Dim rng As Range
Set rng = Selection
If Application.WorksheetFunction.CountBlank(rng) <> 1 Then
MsgBox "Incorrect range selection", vbCritical
Exit Sub
End If
If rng.Row < 5 Or rng.Row > 35 Then
MsgBox "Incorrect range selection", vbCritical
Exit Sub
End If
If rng.Column < 2 Or rng.Column > 30 Then
MsgBox "Incorrect range selection", vbCritical
Exit Sub
End If
If sh.Cells(rng.Row, 1).Value <> Int(Now) Then
MsgBox "You can update the time for today only", vbCritical
Exit Sub
End If
'''''''''''''''''''''
sh.Unprotect "1234"
rng.Value = Now
sh.Protect "1234"
End Sub
Sub Clear_sheet()
Dim sh As Worksheet
Set sh = ActiveSheet
sh.Unprotect "1234"
sh.Range("B5:G35").ClearContents
sh.Protect "1234"
End Sub
the underline VBA code are not working when i put my date in horizontally