Can you please correct the VBA code for check for Today in this event: Private Sub…
- User
Can you please correct the VBA code for check for Today in this event: Private Sub Worksheet_Change(ByVal Target As Range)
' Define the range you want to restrict the code to (adjust as needed) Dim restrictedRange As Range Set restrictedRange = Range("B2:K24") Dim Today As Date Set Today = Today() ' Check if the changed cell is within the restricted range If Not Intersect(Target, restrictedRange) Is Nothing Then ' Proceed with the rest of the code only if the change is within the range If Target.Count > 1 Then Exit Sub ' Exit if multiple cells change ' Get the date in the cell to the right of the changed cell Dim adjacentDate As Date adjacentDate = Target.Offset(0, 1).Value ' Check if the adjacent date is not today or yesterday If adjacentDate <> Today And adjacentDate <> DateAdd("d", -1, Today) Then Application.EnableEvents = False Target.Value = "" ' Clear any entered value MsgBox "Entry is allowed only in the columns for today or yesterday's date." Application.EnableEvents = True End If End IfEnd Sub
- Assistant
Sure, here is the corrected VBA code:
Private Sub Worksheet_Change(ByVal Target As Range) ' Define the range you want to restrict the code to (adjust as needed) Dim restrictedRange As Range Set restrictedRange = Range("B2:K24") ' Check if the changed cell is within the restricted range If Not Intersect(Target, restrictedRange) Is Nothing Then ' Proceed with the rest of the code only if the change is within the range If Target.Count > 1 Then Exit Sub ' Exit if multiple cells change ' Get the current date Dim Today As Date Today = Date ' Get the date in the cell to the right of the changed cell Dim adjacentDate As Date adjacentDate = Target.Offset(0, 1).Value ' Check if the adjacent date is not today or yesterday If adjacentDate <> Today And adjacentDate <> DateAdd("d", -1, Today) Then Application.EnableEvents = False Target.Value = "" ' Clear any entered value MsgBox "Entry is allowed only in the columns for today or yesterday's date." Application.EnableEvents = True End If End If End Sub - User
Hi Bard, In my workbook, there are several sheets that their names end with the word Checks. I want a VBA code that will do the following. In sheet 'Person Responsible' when I enter a value in A2, check the column AB of all sheets that their names end with the word 'Checks' Then for each value in column AB that matches the value entered in sheet 'Person Responsible' A2, copy the value of column A of the same row and list it into sheet 'Person Responsible' from column B2 downwards without any blankcells between the list.
- Assistant