IsEmpty(Target) not working in selected range of cells

nubranger

Board Regular
Joined
Dec 23, 2019
Messages
53
Office Version
  1. 365
Platform
  1. Windows
My code below does a very simple task. It automatically populates 2 cells within the same row of the target when the target cell is not empty and deletes the same values when the target's value gets deleted (empty).

My issue is with the delete code. It works when I delete individual target cells but not in range (e.g., C3 to C10).

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Offset.Row > 5 And Target.Offset.Column = 6 Then
    If Not IsEmpty(Target) Then
 
        Target.Offset(0, -4).Value = Target.Offset.Row - 5
        Target.Offset(0, -3).Value = Format(Now, "mm/dd/yyyy")
        Target.Offset(0, -1).Value = Application.UserName
        
    End If
End If

If Target.Offset.Row > 5 And Target.Offset.Column = 6 Then
    If IsEmpty(Target) Then
 
        Target.Offset(0, -4).Value = ""
        Target.Offset(0, -3).Value = ""
        Target.Offset(0, -1).Value = ""
        
    End If
End If

End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
That is not what IsEmpty is meant for,

You need to loop through the cells and check if each cell is <>"" or =""
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
For Each c In Target
    If c.Row > 5 And c.Column = 6 Then
        If c.Value <> "" Then
            c.Offset(0, -4).Value = c.Offset.Row - 5
            c.Offset(0, -3).Value = Format(Now, "mm/dd/yyyy")
            c.Offset(0, -1).Value = Application.UserName
        Else
            c.Offset(0, -4).ClearContents
            c.Offset(0, -3).ClearContents
            c.Offset(0, -1).ClearContents
        End If
    End If
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,647
Messages
6,120,722
Members
448,987
Latest member
marion_davis

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