Please can you modify the VBA below to do the following:
For assetEventsRow = 2 To lastRow
If IsDate(wsAssetEvents.Cells(assetEventsRow, "D").Value) Then
If wsAssetEvents.Cells(assetEventsRow, "D").Value >= startOfWeek And _
wsAssetEvents.Cells(assetEventsRow, "D").Value <= endOfWeek And _
wsAssetEvents.Cells(assetEventsRow, "D").Value >= currentDate Then
If all the values are False then
' Write headers to Booking sheet
wsBooking.Range("N2").Value = "NO"
wsBooking.Range("O2").Value = "BOOKINGS"
wsBooking.Range("P2").Value = "THIS"
wsBooking.Range("Q2").Value = "WEEK"
and exit the sub.
Option Explicit
Sub ThisWeeksBookings()
Dim wsBooking As Worksheet
Dim wsAssetEvents As Worksheet
Dim lastRow As Long
Dim assetEventsRow As Long
Dim bookingRow As Long
Dim currentDate As Date
Dim startOfWeek As Date
Dim endOfWeek As Date
Dim i As Long
' Set the worksheets
Set wsBooking = ThisWorkbook.Sheets("Booking")
Set wsAssetEvents = ThisWorkbook.Sheets("Asset Events")
' Unlock Booking sheet
wsBooking.Unprotect Password:="edit"
' Calculate and update ranges in Booking sheet
wsBooking.Range("N1:Q1").Calculate
wsBooking.Range("N2:Q40").ClearContents
' Write headers to Booking sheet
wsBooking.Range("N2").Value = "ASSET"
wsBooking.Range("O2").Value = "BOOKING"
wsBooking.Range("P2").Value = "WEEK"
wsBooking.Range("Q2").Value = "DETAILS"
' Get the current week's start and end dates
currentDate = Date
startOfWeek = currentDate - Weekday(currentDate, vbMonday) + 1 ' Adjust to Monday
endOfWeek = startOfWeek + 6
' Initialize the bookingRow for pasting data to Booking sheet
bookingRow = 3
' Find the last row in 'Asset Events' sheet based on column D
lastRow = wsAssetEvents.Cells(wsAssetEvents.Rows.count, "D").End(xlUp).row
' Loop through Asset Events sheet to find dates in the current week
For assetEventsRow = 2 To lastRow
If IsDate(wsAssetEvents.Cells(assetEventsRow, "D").Value) Then
If wsAssetEvents.Cells(assetEventsRow, "D").Value >= startOfWeek And _
wsAssetEvents.Cells(assetEventsRow, "D").Value <= endOfWeek Then
' Copy values from columns C, D, E, G to Booking sheet
wsBooking.Cells(bookingRow, "N").Value = wsAssetEvents.Cells(assetEventsRow, "C").Value ' Asset
wsBooking.Cells(bookingRow, "O").Value = wsAssetEvents.Cells(assetEventsRow, "D").Value ' Date
wsBooking.Cells(bookingRow, "P").Value = wsAssetEvents.Cells(assetEventsRow, "E").Value ' Week
wsBooking.Cells(bookingRow, "Q").Value = wsAssetEvents.Cells(assetEventsRow, "G").Value ' Details
' Increment the bookingRow
bookingRow = bookingRow + 1
End If
End If
Next assetEventsRow
' Lock Booking sheet
wsBooking.Protect Password:="edit"
End Sub