Need value to be the Table Column Header in lieu of Cell Address

sspatriots

Well-known Member
Joined
Nov 22, 2011
Messages
585
Office Version
  1. 365
Platform
  1. Windows
This is the same code I was working with yesterday, except I want to add a column. I've revised the code to add a value in the new column, per the line of code directly below. Currently, as you can see it is returning the cell address of the Target. I need to have this actually provide me the column header name in that table for the column referenced in that cell address. That is, if the cell address Q5 for a cell in the table "G2JobList" has a column header called "Payment", then I need "Payment" to appear in the second column in lieu of the cell address. I've shown my updated code below as well.

Any assistance on this would be much appreciated.


Thanks, SS

VBA Code:
Sheets("LogDetails").Range("A" & Rows.Count).End(xlUp).Offset(0, 1).Value = Target.Address(0, 0)


VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim sSheetName As String
Dim temparr(1 To 1, 1 To 3) As Variant
Dim myRange As Range    'Added, SPS, 10/23/23
Dim tb1 As ListObject
Dim lc1 As ListColumn
Dim tgtJobName As String
Dim BLFormula As String

Set tb1 = Range("G2JobList").ListObject                'Source Table
Set lc1 = tb1.ListColumns("Job Name")
            
tgtJobName = Intersect(Target.EntireRow, lc1.Range).Value
            
BLFormula = "=HYPERLINK(""#""&CELL(""address"",XLOOKUP(RC[-6],Job_Name,G2JobList[Last PMT" & Chr(10) & "Status" & Chr(10) & "Change],""Not found!"",0,1))," & Chr(10) & "" & Chr(10) & "RIGHT(CELL(""address"",XLOOKUP(RC[-6],Job_Name,G2JobList[Last PMT" & Chr(10) & "Status" & Chr(10) & "Change],""Not found!"",0,1))," & Chr(10) & "LEN(CELL(""address"",XLOOKUP(RC[-6],Job_Name,G2JobList[Last PMT" & Chr(10) & "Status" & Chr(10) & "Change],""Not found!"",0,1)))-" & Chr(10) & "SEARCH(""!"",CELL(""address"",XLOOKUP(RC[-6],Job" & _
            "_Name,G2JobList[Last PMT" & Chr(10) & "Status" & Chr(10) & "Change],""Not found!"",0,1)),1))" & Chr(10) & "" & Chr(10) & ")" & _
            ""

Set myRange = Range("G2JobList[[Down" & Chr(10) & "Payment]], G2JobList[[Payment" & Chr(10) & "With" & Chr(10) & "Approval]], G2JobList[[Payment" & _
Chr(10) & "Before" & Chr(10) & "Shipping]]")

    If Target.Count > 1 Then Exit Sub
    If Intersect(Target, myRange) Is Nothing Then Exit Sub

    oldAddress = Target.Address

sSheetName = "Jobs"

If ActiveSheet.Name <> "LogDetails" Then
Application.EnableEvents = False

Sheets("LogDetails").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = tgtJobName
Sheets("LogDetails").Range("A" & Rows.Count).End(xlUp).Offset(0, 1).Value = Target.Address(0, 0)
Sheets("LogDetails").Range("A" & Rows.Count).End(xlUp).Offset(0, 2).Value = oldValue
Sheets("LogDetails").Range("A" & Rows.Count).End(xlUp).Offset(0, 3).Value = Target.Value
Sheets("LogDetails").Range("A" & Rows.Count).End(xlUp).Offset(0, 4).Value = Environ("username")
Sheets("LogDetails").Range("A" & Rows.Count).End(xlUp).Offset(0, 5).Value = Now
Sheets("LogDetails").Range("A" & Rows.Count).End(xlUp).Offset(0, 6).Value = BLFormula
Sheets("LogDetails").Columns("A:G").AutoFit

Application.EnableEvents = True

End If

End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I played around with it long enough and came up with the following for that line of code:

VBA Code:
Sheets("LogDetails").Range("A" & Rows.Count).End(xlUp).Offset(0, 1).Value = Cells(2, Target.Column).Value


It seems to have worked very well.
 
Upvote 0
Solution

Forum statistics

Threads
1,224,812
Messages
6,181,099
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