Excel 365 VBA module Identify value in first column of Table

DThib

Active Member
Joined
Mar 19, 2010
Messages
464
Office Version
  1. 365
Platform
  1. Windows
Hello,

I cannot remember how to write the code for this one thing.
I have a workbook with tables and have a sheet holding the Audit trail data. All is pulling correctly, but I need to have it identify the text in the first column of data when it finds the address that is identifying as the changed data.
The identity of the target.address is always changing because it is accounting for all changes, but I need the first column text for each entry. Can anyone help me sate this correctly.

Help?
VBA Code:
Dim PreviousValue
Private Sub Worksheet_Change(ByVal Target As Range)

Dim i As Long
Dim ws As Worksheet

Set ws = Sheets("Audit Trail")

i = ws.Range("F" & Rows.Count).End(xlUp).Row + 1

If Target.Value <> PreviousValue Then
    
    With ws
        .Range("B" & i).Value = FormatDateTime(Now, vbShortDate)
        .Range("C" & i).Value = FormatDateTime(Now, vbLongTime)
        .Range("D" & i).Value = Environ$("username")
        .Range("E" & i).Value = ActiveSheet.Name
        .Range("F" & i).Value = Target.Address
        .Range("G" & i).Value = PreviousValue
        .Range("H" & i).Value = Target.Value
       '.Range("I" & i).Value =
    End With
End If

End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   
   PreviousValue = Target.Value
   
End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Can anyone help? The row is defined by the Target, I need to call on column 1 in that row to get the text.

Thib
 
Upvote 0
So, the problem is, the target address shows the position of the information that has changed and the previous and new information.
I cannot figure out how to take the target row and apply it to the information in column 1 of the table to another table field in the Audit file.

Help, please
 
Upvote 0
Can anyone help? The row is defined by the Target, I need to call on column 1 in that row to get the text.
Try this:
VBA Code:
Cells(Target.Row, 1)
 
Upvote 0
Solution
You are welcome!
Glad I was able to help!

Many times, I prefer using "Cells" over "Range", as with "Cells", you can refer to columns by either their column name ("A") or by their numerical position (1).

So:
VBA Code:
Cells(Target.Row, 1)
and
VBA Code:
Cells(Target.Row, "A")
really mean the same thing.
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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