Selecting specific cells in a table row using vba, where user has manually selected the row.
User will select a particular row in a table, and I need to take the data from 8 cells in that row, and put them on a different sheet.
I need to use structured formatting (which I believe is using the column labels) within the vba code,
as the Table may have additional columns added in the future, and I don't want to re-adjust the cell references each time.
I have cobbled together this code from various sources, which actually works, but I think it is possibly overkill?
Is there simpler code that I should be using?
Any pointers would be appreciated...
User will select a particular row in a table, and I need to take the data from 8 cells in that row, and put them on a different sheet.
I need to use structured formatting (which I believe is using the column labels) within the vba code,
as the Table may have additional columns added in the future, and I don't want to re-adjust the cell references each time.
I have cobbled together this code from various sources, which actually works, but I think it is possibly overkill?
Is there simpler code that I should be using?
Code:
Sub Populate_JI_Sheet()
Dim csd As Range 'Course Start Date
Dim v As Range 'Venue
Dim st As Range 'Start Time
Dim d As Range 'Duration
Dim a As Range 'Activity
Dim e As Range 'Email
Dim fn As Range 'First name
Dim ln As Range 'Last name
Set csd = Evaluate("Table1[[#This Row], [Course Start Date]]")
Sheets("JI_Sheet").Range("C8").Value = csd
Set v = Evaluate("Table1[[#This Row], [Venue]]")
Sheets("JI_Sheet").Range("C9").Value = v
Set st = Evaluate("Table1[[#This Row], [Start Time]]")
Sheets("JI_Sheet").Range("C10").Value = st
Set d = Evaluate("Table1[[#This Row], [Duration]]")
Sheets("JI_Sheet").Range("C11").Value = d
Set a = Evaluate("Table1[[#This Row], [Activity]]")
Sheets("JI_Sheet").Range("C7").Value = a
Set e = Evaluate("Table1[[#This Row], [Contact Details]]")
Sheets("JI_Sheet").Range("J3").Value = e
Set fn = Evaluate("Table1[[#This Row], [First Name]]")
Set ln = Evaluate("Table1[[#This Row], [Last Name]]")
Sheets("JI_Sheet").Range("J4").Value = fn & " " & ln
End Sub
Any pointers would be appreciated...