Any help much appreciated. I have a spreadsheet and a worksheet change event which checks Column B and show's a message box when either "Personal" or "Corporate" is entered in the cell. It uses an OldValue variable to ensure the macro doesnt fire when the change is occurring to a currently blank cell.
What I also need the macro to do is to also delete the contents of columns D, E and F in the row corresponding to the cell whenever "Personal" or "Corporate" is entered in the cell. Code below.
Public OldValue As String
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("B2:BF" & Rows.Count)) Is Nothing Then Exit Sub
With Application
On Error GoTo ErrHandler
.EnableEvents = False
.Undo
OldValue = Target.Cells(1).Value
.Undo
.EnableEvents = True
ActiveCell.Offset(0, 1).Select
End With
With Target
If OldValue = "Personal" Then MsgBox "Please note products available are specific to either Personal or Corporate applications."
If OldValue = "Corporate" Then MsgBox "Please note products available are specific to either Personal or Corporate applications."
End With
ErrHandler:
Application.EnableEvents = True
If Err.Number <> 0 Then
MsgBox "Error: " & Err.Number & vbNewLine & Err.Description
End If
End Sub
What I also need the macro to do is to also delete the contents of columns D, E and F in the row corresponding to the cell whenever "Personal" or "Corporate" is entered in the cell. Code below.
Public OldValue As String
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("B2:BF" & Rows.Count)) Is Nothing Then Exit Sub
With Application
On Error GoTo ErrHandler
.EnableEvents = False
.Undo
OldValue = Target.Cells(1).Value
.Undo
.EnableEvents = True
ActiveCell.Offset(0, 1).Select
End With
With Target
If OldValue = "Personal" Then MsgBox "Please note products available are specific to either Personal or Corporate applications."
If OldValue = "Corporate" Then MsgBox "Please note products available are specific to either Personal or Corporate applications."
End With
ErrHandler:
Application.EnableEvents = True
If Err.Number <> 0 Then
MsgBox "Error: " & Err.Number & vbNewLine & Err.Description
End If
End Sub