Deleting vs Clear Contents

RandyD123

Active Member
Joined
Dec 4, 2013
Messages
289
Office Version
  1. 2016
Platform
  1. Windows
I have this line of code in my worksheet:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Intersect(Target, Range("C4:C1002")) Is Nothing Then Exit Sub
  If Target.Count > 1 Then Exit Sub
 
  Application.EnableEvents = False
 
  With Target
    If .Value = "" Then
      .Offset(, 6).Value = ""
      .Offset(, 7).Value = ""
      .Offset(, 8).Value = ""
    Else
      .Offset(, 6).Value = Environ("username")
      .Offset(, 7).Value = Date
      .Offset(, 8).Value = Time
    End If
  End With
  Application.EnableEvents = True
End Sub

It works great to delete the entries in columns I, J and K.....IF I backspace the entry out in any cell in my C column. But if I "clear contents" of any cell in my C column the entries remain in my last 3 columns. How can I fix this to work so no matter what I do..... clear or delete or cut and paste somewhere else if the value in any cell in the C column is blank then it clears the entries in my last 3 columns?

Thanks in advance.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Try:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
If Not Intersect(Target, Range("C4:C1002")) Is Nothing Then
    Application.EnableEvents = False
    For Each c In Intersect(Target, Range("C4:C1002"))
        With c
          If .Value = "" Then
            .Offset(, 6).Value = ""
            .Offset(, 7).Value = ""
            .Offset(, 8).Value = ""
          Else
            .Offset(, 6).Value = Environ("username")
            .Offset(, 7).Value = Date
            .Offset(, 8).Value = Time
          End If
        End With
    Next c
End If
Application.EnableEvents = True
End Sub
 
Upvote 0
Solution
Try:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
If Not Intersect(Target, Range("C4:C1002")) Is Nothing Then
    Application.EnableEvents = False
    For Each c In Intersect(Target, Range("C4:C1002"))
        With c
          If .Value = "" Then
            .Offset(, 6).Value = ""
            .Offset(, 7).Value = ""
            .Offset(, 8).Value = ""
          Else
            .Offset(, 6).Value = Environ("username")
            .Offset(, 7).Value = Date
            .Offset(, 8).Value = Time
          End If
        End With
    Next c
End If
Application.EnableEvents = True
End Sub
Works perfectly, Thank You!!!
 
Upvote 0

Forum statistics

Threads
1,214,659
Messages
6,120,783
Members
448,992
Latest member
prabhuk279

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top