Skip to content

Instantly share code, notes, and snippets.

@pohzipohzi
Created November 6, 2017 07:59
Show Gist options
  • Save pohzipohzi/1f67d5c6b230ba610e7dd48d39b111a9 to your computer and use it in GitHub Desktop.
Save pohzipohzi/1f67d5c6b230ba610e7dd48d39b111a9 to your computer and use it in GitHub Desktop.
Simple template for looping through table objects in excel
Sub tableloop()
Dim tbl As ListObject
Set tbl = ThisWorkbook.Worksheets("wsname").ListObjects("tblname")
Dim i As Integer
For i = 1 To tbl.ListRows.Count
Dim col1val, col2val As String
col1val = Trim(tbl.ListColumns("col1name").DataBodyRange(i, 1).Value)
col2val = Trim(tbl.ListColumns("col2name").DataBodyRange(i, 1).Value)
'do stuff with column values here
Next i
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment