CascadeDiver
Board Regular
- Joined
- Apr 10, 2020
- Messages
- 62
- Office Version
- 2016
- Platform
- Windows
Hi all.
I'm trying to learn some basics on looping and List Objects.
I've created a simple loop that displays data from a selected range into a new field. It works just fine however I think there is a way I can replace the .Offset using ListRow but I'm not sure how. The reason for wanting to do away with the .Offset is for the ability to move the tables elsewhere.
As the photo shows. When a cell in the MainTable is selected the data repopulates in the RefTable
I'm trying to learn some basics on looping and List Objects.
I've created a simple loop that displays data from a selected range into a new field. It works just fine however I think there is a way I can replace the .Offset using ListRow but I'm not sure how. The reason for wanting to do away with the .Offset is for the ability to move the tables elsewhere.
VBA Code:
Option Explicit
Sub Load_Data()
Dim MainTable As ListObject
Set MainTable = Sheet1.ListObjects("Main_Table")
Dim RefTable As Range
Set RefTable = Sheet1.ListObjects("Review_Table").ListRows(1).Range
Dim SelectedRow As Long
SelectedRow = ActiveCell.Row
Dim EntryCol As Integer
For EntryCol = 1 To 3
RefTable.Cells(1, EntryCol).Value = MainTable.Range(SelectedRow, EntryCol).Offset(-6, 0).Value
Next EntryCol
End Sub
As the photo shows. When a cell in the MainTable is selected the data repopulates in the RefTable