update table row automatically

mariatti

New Member
Joined
Sep 22, 2023
Messages
11
Office Version
  1. 2021
Platform
  1. Windows
I have a table called GastosCC with 3 columns. These Columns are: DATA, VALOR and ITEM.
When I change a value in the VALOR column, I want the DATE column to be updated, on the same line as the VALOR column change, with the update date.
I did this code, it doesn't show any errors when saving, but it doesn't update the DATA column line.
thanks for the help

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim GastosCC As ListObject
    Dim Cell As Range
    
    Set GastosCC = Me.ListObjects("GastosCC") '
    If Not Intersect(Target, GastosCC.ListColumns("VALOR").DataBodyRange) Is Nothing Then
        Application.EnableEvents = False
        For Each Cell In Target
            If Not IsEmpty(Cell.Value) Then
                 Cell.Offset(0, -1).Value = Now
            End If
        Next Cell
        Application.EnableEvents = True
    End If
End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Try something like this:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim GastosCC As ListObject
    
    Set GastosCC = Me.ListObjects("GastosCC") '
    If Not Intersect(Target, GastosCC.ListColumns("VALOR").DataBodyRange) Is Nothing Then
        Application.EnableEvents = False
                 Target.Offset(0, -1).Value = Now
        Application.EnableEvents = True
    End If
End Sub
 
Upvote 1
Solution
Try something like this:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim GastosCC As ListObject
   
    Set GastosCC = Me.ListObjects("GastosCC") '
    If Not Intersect(Target, GastosCC.ListColumns("VALOR").DataBodyRange) Is Nothing Then
        Application.EnableEvents = False
                 Target.Offset(0, -1).Value = Now
        Application.EnableEvents = True
    End If
End Sub
ty bro, work!
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,161
Members
453,021
Latest member
Justyna P

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