I am trying to loop through the cells of several copied listobjects (table) in a workbook
The problem I run into is that the cell references of the "(each) cell loop" are different from the listobject.range.cell/row references, and equal to the offset/references of the first cell of the listobject. (so no problem when the listobjects start at A1)
To investigate I created two listobjects mylo1 and mylo2 of 4x4 cells, starting on B3 and the second on G4 somewhere in a workbook. I then populated the cells of each listobject with the same data, (AA, BB, CC, DD, FF, GG, HH, II, JJ, etc), and had the headers created by excel when converting the range to a table. For ease of use I name listobjects.
In vba I investigated the issue with message boxes:
The result should be that both msgboxes display the same reference values for the same cell, or at least that is what I expect and need, however immediately the first run gives me
$B$3, $C$5
It looks as if the reference of the "for each cell" is absolute, while the cell reference of the listobject is relative, or offset with the reference of the first cell of the loop.
The question is how I can loop through the first listobject (for each) and use the reference from the current cell to reference the corresponding cell in the second listobject.
P.S. the listobjects could be anywhere in the workbook, I reference by listobject name to avoid having to physically locate the listobjects.
Anyone who understands what's going on or how I could alleviate the issue?
Thanks.
The problem I run into is that the cell references of the "(each) cell loop" are different from the listobject.range.cell/row references, and equal to the offset/references of the first cell of the listobject. (so no problem when the listobjects start at A1)
To investigate I created two listobjects mylo1 and mylo2 of 4x4 cells, starting on B3 and the second on G4 somewhere in a workbook. I then populated the cells of each listobject with the same data, (AA, BB, CC, DD, FF, GG, HH, II, JJ, etc), and had the headers created by excel when converting the range to a table. For ease of use I name listobjects.
In vba I investigated the issue with message boxes:
Code:
For Each cell_1 In mylo_1.Range
MsgBox cell_1.Address, vbOKOnly, "Plain"
MsgBox mylo_1.Range(cell_1.Row, cell_1.Column).Address, vbOKOnly, "Lo address"
Next
The result should be that both msgboxes display the same reference values for the same cell, or at least that is what I expect and need, however immediately the first run gives me
$B$3, $C$5
It looks as if the reference of the "for each cell" is absolute, while the cell reference of the listobject is relative, or offset with the reference of the first cell of the loop.
The question is how I can loop through the first listobject (for each) and use the reference from the current cell to reference the corresponding cell in the second listobject.
P.S. the listobjects could be anywhere in the workbook, I reference by listobject name to avoid having to physically locate the listobjects.
Anyone who understands what's going on or how I could alleviate the issue?
Thanks.