Consulting

Results 1 to 5 of 5

Thread: Do not update range if cell is not empty

  1. #1
    VBAX Regular
    Joined
    Dec 2020
    Posts
    48
    Location

    Do not update range if cell is not empty

    Howdi,

    Have this code to Add the date and time into column C when the 'Change Number' cell is changed.

    However i don't want this to update if there is already a date in column C...im stumped!

    Hope you can help


    Private Sub Worksheet_Change(ByVal Target As Range)Dim r As Range, Intersection As Range, cell As Range
        Set r = Range("ChgTBL[Change Number]")
        Set Intersection = Intersect(r, Target)
    
    
        If Intersection Is Nothing Then Exit Sub
    
    
        Application.EnableEvents = False
            For Each cell In Intersection
                Range("C" & cell.Row).Value = Date + Time
                Range("D" & cell.Row).Value = Application.UserName
            Next cell
        Application.EnableEvents = True
    
    
    
    
    End Sub

  2. #2
    Private Sub Worksheet_Change(ByVal Target As Range)Dim r As Range, Intersection As Range, cell As Range
        Set r = Range("ChgTBL[Change Number]")
        Set Intersection = Intersect(r, Target)
    
    
    
    
        If Intersection Is Nothing Then Exit Sub
    
    
    
    
        Application.EnableEvents = False
            For Each cell In Intersection
    		If Len(Range("C" & cell.Row) & "") = 0 Then
                		Range("C" & cell.Row).Value = Date + Time
    		End If
    		If Len(Range("D" & cell.Row) & "") = 0 Then
                		Range("D" & cell.Row).Value = Application.UserName
    		End If
            Next cell
        Application.EnableEvents = True
    End Sub

  3. #3
    VBAX Regular
    Joined
    Dec 2020
    Posts
    48
    Location
    Thankyou Arnelgp! that works perfectly!!

    Just another thing i've noticed is it records a change event when the table is expanded or when you just click in the Change Number column. Is there a way to not run the event until a value greater than 0 is added?

  4. #4
    the event wil Fire whenever you change any cell in the worksheet
    regardless if it is numeric or string that you add/edit .

  5. #5
    VBAX Regular
    Joined
    Dec 2020
    Posts
    48
    Location
    Ah ok, thanks for support and responses. Its working great

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •