Private Sub Worksheet_Change(ByVal Target As Range) Dim answer As VbMsgBoxResult Dim…
- User
Private Sub Worksheet_Change(ByVal Target As Range) Dim answer As VbMsgBoxResult Dim contractor As String Dim wpSheet As Worksheet Dim lastRow As Long ' Check for text entered in column J If Target.Column = 10 And Target.Value <> "" Then ' Ask user if they want to send details to contractor answer = MsgBox("Would you like to send details to the contractor?", vbYesNo + vbQuestion, "Send details") If answer = vbYes Then ' Store details from current sheet in variables contractor = ActiveSheet.Name ' If you have other details to store, add them here
' Activate Work Permit sheet Set wpSheet = ThisWorkbook.Sheets("Work Permit") wpSheet.Activate ' Copy data from previous sheet lastRow = wpSheet.Cells(wpSheet.Rows.Count, "A").End(xlUp).Row + 1
wpSheet.Cells(lastRow, "A").Value = Target.Value wpSheet.Cells(lastRow, "B").Value = ThisWorkbook.Sheets(contractor).Range("B1").Value wpSheet.Cells(lastRow, "C").Value = ThisWorkbook.Sheets(contractor).Cells(Target.Row, "C").Value
End If End If End Sub
Apart from checking if the Target.Column = 10 And Target.Value <> "" I want the code to check both E1 and G1 in the active sheet to see if they have values displayed. If E1 does not display a value the MsgBox sholud state "Contractor is not Insured - would you like to send details?" If G1 does not dispaly a value the MsgBox sholud state "Contractor is not DBS Cleared - would you like to send details?" If both E1 and G1 do not dispaly a value the MsgBox sholud state "Contractor is not Insured nor DBS Cleared - would you like to send details?" If I answer Yes to any of the prompts the code will Activate Work Permit sheet and continue with the part that reads Set wpSheet = This Workbook.Sheets("Work Permit")
- Assistant
Here is the updated code that includes the additional checks:
Private Sub Worksheet_Change(ByVal Target As Range) Dim answer As VbMsgBoxResult Dim contractor As String Dim wpSheet As Worksheet Dim lastRow As Long ' Check for text entered in column J If Target.Column = 10 And Target.Value <> "" Then
code - User
can you make a correction to the code, so that if both E1 and G1 both have values in them rest of the macro is skipped
- Assistant
Sure, here's the updated code that skips the macro if both E1 and G1 have values.
Private Sub Worksheet_Change(ByVal Target As Range) Dim answer As VbMsgBoxResult Dim contractor As String Dim wpSheet As Worksheet Dim lastRow As Long