Iterating through Workbook Tables

Nothing special just want to put a culmination of information available out there into one useful code-snippet

1:  Dim wb As Workbook  
2:  Set wb = ActiveWorkbook  
3:  Dim ws As Worksheet  
4:  Dim lo As ListObject  
5:  Dim lc As ListColumn  
6:  Dim lr As ListRow  
7:  Dim frm As New frmListRanges  
8:  Dim txt As String  
9:    
10:  For Each ws In wb.Worksheets  
11:     For Each lo In ws.ListObjects  
12:        txt = ""  
13:        For Each lr In lo.ListRows  
14:           txt = "{ "  
15:           For Each lc In lo.ListColumns  
16:              txt = txt & " " & CStr(lo.DataBodyRange.Cells(lr.Index, lc.Index).Value) & ","  
17:           Next lc  
18:           Trim (txt)  
19:           If StrComp(Right(txt, 0), ",", vbTextCompare) Then  
20:              txt = Left(txt, Len(txt) - 1)  
21:           End If  
22:           txt = txt & " }"  
23:           frm.AddNamedRange ("WS: " & ws.Name & " - LO: " & lo.Name & " " & txt)  
24:        Next lr  
25:     Next lo  
26:  Next ws  
27:    
28:  frm.Show  

Comments

Popular posts from this blog

SysInternals - BgInfo for ALL Users

JSON/AJAX Helpers

Acquiring List of controls - Classic JS