Timestamp Issues

AudBall

New Member
Joined
Oct 2, 2015
Messages
24
Hi MrExcel community,

I've used the following code a few times to get a timestamp when a range of noncontiguous cells are populated. However, now I'm trying to get the timestamp to clear if any one of the populated cells within the range is cleared. Currently, the timestamp only clears if when the first cell in the range is cleared. My understanding is that vbEmpty doesn't work with noncontiguous ranges. Unfortunately, my attempts to use Boolean values and assigning it to a variable have proven unsuccessful.

Any assistance would be greatly appreciated.

Thank you.


Code:
Private Sub Worksheet_Change(ByVal target As Range)
Dim MyRange1 As Range
Dim MyDate1 As Range
Dim MyUser1 As Range

    Set MyRange1 = Range("F10, F12, F18, F20, G10, G12, G14, G16, G18, G20, H10, H16, I10, I14, I20, J10, K18:K20")
    Set MyDate1 = Range("F23")
    Set MyUser1 = Range("F22")
        
     If Not Intersect(target, MyRange1) Is Nothing Then
         
         If MyRange1 = vbEmpty Then
            'ActiveSheet.Unprotect Password:="12345"
            MyDate1.ClearContents
            MyUser1.ClearContents
            'ActiveSheet.Protect Password:="12345", DrawingObjects:=True, Contents:=True, Scenarios:= _
            True
            'ActiveSheet.EnableSelection = xlUnlockedCells
         End If
         
         For Each cel In MyRange1
            If cel = "" Then Exit Sub
         Next cel
            'ActiveSheet.Unprotect Password:="12345"
            MyDate1 = Date & " " & Time
            MyUser1 = Application.UserName
            'ActiveSheet.Protect Password:="12345", DrawingObjects:=True, Contents:=True, Scenarios:= _
            True
            'ActiveSheet.EnableSelection = xlUnlockedCells
     
     End If
  
        
End Sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Replace:
Code:
If MyRange1 = vbEmpty Then
with
Code:
If target = "" Then
 
Upvote 0
So, that did fix the initial issue. However, if I delete the contents of multiple cells at the same time, I get a Run Time Error: 13 - Type Mismatch on
Code:
If target = "" Then
.
 
Upvote 0

Forum statistics

Threads
1,214,636
Messages
6,120,664
Members
448,976
Latest member
sweeberry

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