Insert / Update datetime on active row when changes are made in a range

sashapixie

Board Regular
Joined
Aug 29, 2013
Messages
71
Office Version
  1. 365
Platform
  1. Windows
Hi

I have some VBA to insert / update a column on the active row when changes are made within a range on the active row. The vba is working when I use cell references, however when I use table named ranges it errors.

Private Sub Worksheet_Change(ByVal Target As Range)



'Update CRM date when cells change in CRM range
Dim CRM As Range, CRM_Rng As Range, Update_CRM As Range, CRM_l As Long, CRM_Cells As String


CRM_l = ActiveCell.Row
CRM_Cells = "mapping_table[CRM - Updated Date]" & CRM_l


Set CRM = Intersect(Application.ActiveSheet.Range("mapping_table[[CRM - Table Name (M)]:[CRM - Developer]]"), Target)
Set Update_CRM = Range(CRM_Cells)
If Not CRM Is Nothing Then
Application.EnableEvents = False
For Each CRM_Rng In CRM
If Not VBA.IsEmpty(CRM_Rng.Value) Then
Update_CRM.Value = Now
Update_CRM.NumberFormat = "dd-mm-yyyy, hh:mm:ss"
Else
Update_CRM.ClearContents
End If
Next
Application.EnableEvents = True
End If
End Sub

Can anyone help please
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
How about
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Update CRM date when cells change in CRM range
Dim CRM As Range, CRM_Rng As Range, Update_CRM As Range, CRM_l As Long, CRM_Cells As String


CRM_l = Target.Row


Set CRM = Intersect(Range("mapping_table[[CRM - Table Name (M)]:[CRM - Developer]]"), Target)
Set Update_CRM = Me.ListObjects("mapping_table").ListColumns("CRM - Updated Date").DataBodyRange
If Not CRM Is Nothing Then
    Application.EnableEvents = False
    For Each CRM_Rng In CRM
        If Not IsEmpty(CRM_Rng.Value) Then
            With Intersect(Update_CRM, CRM_Rng.EntireRow)
                .Value = Now
                .NumberFormat = "dd-mm-yyyy, hh:mm:ss"
            End With
        Else
            Intersect(Update_CRM, CRM_Rng.EntireRow).ClearContents
        End If
    Next CRM_Rng
    Application.EnableEvents = True
End If
End Sub
 
Upvote 0
How about
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Update CRM date when cells change in CRM range
Dim CRM As Range, CRM_Rng As Range, Update_CRM As Range, CRM_l As Long, CRM_Cells As String


CRM_l = Target.Row


Set CRM = Intersect(Range("mapping_table[[CRM - Table Name (M)]:[CRM - Developer]]"), Target)
Set Update_CRM = Me.ListObjects("mapping_table").ListColumns("CRM - Updated Date").DataBodyRange
If Not CRM Is Nothing Then
    Application.EnableEvents = False
    For Each CRM_Rng In CRM
        If Not IsEmpty(CRM_Rng.Value) Then
            With Intersect(Update_CRM, CRM_Rng.EntireRow)
                .Value = Now
                .NumberFormat = "dd-mm-yyyy, hh:mm:ss"
            End With
        Else
            Intersect(Update_CRM, CRM_Rng.EntireRow).ClearContents
        End If
    Next CRM_Rng
    Application.EnableEvents = True
End If
End Sub

Perfect!!

Thank you :)
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

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