In the VBA code below, can I please have two chages. When it clears the contents of…
- User
In the VBA code below, can I please have two chages. When it clears the contents of A2:H32, can it also clear any existing comments ' Clear Contents of Week Events wsWeekEvent.Range("A2:H32").ClearContents
And where it copies the range from Asset Events to Week Event, can it be structured to copy values only. ' Copy the row from Asset Events to Week Event wsAssetEvents.Range("A" & i & ":H" & i).Copy Destination:=wsWeekEvent.Range("A" & lastRowWeekEvent)
Sub CopyToWeekAndSort()
codeDim wsAssetEvents As Worksheet Dim wsWeekEvent As Worksheet Dim lastRowAssetEvents As Long Dim lastRowWeekEvent As Long Dim i As Long ' Set references to worksheets Set wsAssetEvents = ThisWorkbook.Worksheets("Asset Events") Set wsWeekEvent = ThisWorkbook.Worksheets("Week Events") ' Clear Contents of Week Events wsWeekEvent.Range("A2:H32").ClearContents ' Find the last row in Asset Events lastRowAssetEvents = wsAssetEvents.Cells(wsAssetEvents.Rows.count, "D").End(xlUp).row ' Loop through rows in Asset Events For i = 2 To lastRowAssetEvents ' Check if date is equal to today or greater than today + 9 If wsAssetEvents.Cells(i, "D").Value >= Date And wsAssetEvents.Cells(i, "D").Value <= Date + 9 Then ' Find the next available row in Week Event lastRowWeekEvent = wsWeekEvent.Cells(wsWeekEvent.Rows.count, "A").End(xlUp).row + 1 ' Copy the row from Asset Events to Week Event wsAssetEvents.Range("A" & i & ":H" & i).Copy Destination:=wsWeekEvent.Range("A" & lastRowWeekEvent) End If Next iApplication.Wait (Time + TimeValue("00:00:01")) ' Sort the range in Week Event by column D and then by column F With wsWeekEvent .Range("A1:H" & lastRowWeekEvent).Sort Key1:=.Range("D1:D" & lastRowWeekEvent), _ Key2:=.Range("F1:F" & lastRowWeekEvent), _ Order1:=xlAscending, Order2:=xlAscending, Header:=xlYes End With Application.Wait (Time + TimeValue("00:00:01")) Call InsertMissingDates End Sub
- Assistant
- User
In the VBA code below, can I please have a change. Before the particular word file 'BookingReminder.docm' is opened by the VBA check if it is already open, and if it is close it without saving, wait one second then continue with the rest of the code.
Sub SendBookingReminder() Dim wdApp As Object Dim wdDoc As Object Dim WsdShell As Object Set wdApp = CreateObject("Word.Application") Dim filePath As String filePath = ThisWorkbook.Path & "\BookingReminder.docm" Set wdDoc = wdApp.Documents.Open(filePath) wdApp.Visible = True Set WsdShell = CreateObject("WScript.Shell") WsdShell.AppActivate wdApp.Caption MsgBox "Booking Request Send Email Created", vbInformation, "EMAIL BOOKING REMINDER" Call Module4.EnableManualMainEvents End Sub
- Assistant
To implement the changes you've requested in the VBA code, you will need to:
- User
In the VBA code below, can I please have a change. When I double click, check if the Target has a comment. If it does not continue with the rest of the VBA. If it does have a comment, pop up a Yes No message, with the comments text & " Do you want to re-send" If Yes, delete the comment and continue with the rest of the code. If No, exit the sub
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) If Target.Column = 7 And Target.row > 1 And Not IsEmpty(Target) Then Me.Unprotect Password:="edit" ' Copy the range from A to H Target.Offset(, -6).Resize(, 8).Copy ' Paste values only to I1:P1 Range("I1:P1").PasteSpecial xlPasteValues ' Add a comment to the Target with the message Target.AddComment Text:="Booking Reminder Sent " & Format(Date, "dd/mm/yy") End If Me.Protect Password:="edit" Application.Wait (Time + TimeValue("00:00:01")) Call SendBookingReminder End Sub
- Assistant
- User
Please can you write me a VBA module that will do the following.
In my sheet 'Week Events' determine the range B1:H that contains values and only print the range with values
- Assistant
Certainly! Below is a VBA module that you can use to determine the range in the "Week Events" sheet that contains values from columns B to H. The module will then print that range.