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

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
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,223,893
Messages
6,175,242
Members
452,623
Latest member
russelllowellpercy

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