Please write an excel VBA to do the following. When I enter an email address in sheet…
- User
Please write an excel VBA to do the following. When I enter an email address in sheet 'Booking' A27 search for the match in sheet 'Contacts' column B if found, copy the text value only in column A of the same row in the sheet 'Contacts' to A28 in sheet 'Booking'
- Assistant
- User
In the following VBA code, when there is an entry on the last row of A to H that needs to be sorted, it does it correctly, sorting the entire table range A to H. However, the last value in column G is retained on the last row.
Private Sub Worksheet_Activate() Dim ws As Worksheet Dim lastRow As Long Dim i As Long Dim currentDate As Date Dim startOfWeek As Date
Application.EnableEvents = False ' Set the worksheet Set ws = ThisWorkbook.Worksheets("Asset Events") ' Find the last row in column E lastRow = ws.Cells(ws.Rows.count, "E").End(xlUp).Row With ws .Range("A1:H" & lastRow).Sort Key1:=.Range("D1:D" & lastRow), _ Key2:=.Range("F1:F" & lastRow), _ Order1:=xlAscending, Order2:=xlAscending, Header:=xlYes End With Application.Wait (Time + TimeValue("00:00:01")) ' Get the current date and the start of the current week (Monday) currentDate = Date startOfWeek = currentDate - Weekday(currentDate, vbMonday) + 1 ' Loop through rows from the last to the second For i = lastRow To 2 Step -1 ' Check if the value in column E is a date and if it is before the start of the week If IsDate(ws.Cells(i, "E").Value) Then If ws.Cells(i, "E").Value < startOfWeek Then ' Delete the entire row if the date is before the current week ws.Rows(i).Delete End If End If Next i Application.Wait (Time + TimeValue("00:00:01")) ' Set "Wrap Text" to True for all cells in column G ws.Columns("G").WrapText = True Application.EnableEvents = True - Assistant