Tabellen - Loop through Rows
Dim n As Long
‘Loop Through Each Row in Table
For n = 1 To Sheets(“FTR”).ListObjects(“Table1”).Range.Rows.Count
MsgBox n
Next n
Tabellen - Loop through Columns
‘Loop Through Each Column in Table
For n = 1 To Sheets(“FTR”).ListObjects(“Table1”).ListColumns.Count
MsgBox Sheets(“FTR”).ListObjects(“Table1”).ListColumns(n).Name
Next n
Tabellen - Delete Data from table
Sheets(“FTR”).ListObjects(“Table1”).DataBodyRange.Rows.Delete
Tabellen - Looking Up Values Within a Table
Sub LookupTableValue()
Dim tbl As ListObject
Dim FoundCell As Range
Dim LookupValue As String
‘Lookup Value
LookupValue = “ID-123”
‘Store Table Object to a variable
Set tbl = ActiveSheet.ListObjects(“Table1”)
‘Attempt to find value in Table’s first Column
On Error Resume Next
Set FoundCell = tbl.DataBodyRange.Columns(1).Find(LookupValue, LookAt:=xlWhole)
On Error GoTo 0
‘Return Table Row number if value is found
If Not FoundCell Is Nothing Then
MsgBox “Found in table row: ” & _
tbl.ListRows(FoundCell.Row – tbl.HeaderRowRange.Row).Index
Else
MsgBox “Value not found”
End If
End Sub
Tabellen - Reading Table Data into an Array Variable
Sub SingleColumnTable_To_Array()
Dim myTable As ListObject
Dim myArray As Variant
Dim TempArray As Variant
Dim x As Long
‘Set path for Table variable
Set myTable = ActiveSheet.ListObjects(“Table1”)
‘Create Array List from Table
TempArray = myTable.DataBodyRange
‘Convert from vertical to horizontal array list
myArray = Application.Transpose(TempArray)
‘Loop through each item in the Table Array (displayed in Immediate Window [ctrl + g])
For x = LBound(myArray) To UBound(myArray)
Debug.Print myArray(x)
Next x
End Sub
Sub MultiColumnTable_To_Array()
Dim myTable As ListObject
Dim myArray As Variant
Dim x As Long
‘Set path for Table variable
Set myTable = ActiveSheet.ListObjects(“Table1”)
‘Create Array List from Table
myArray = myTable.DataBodyRange
‘Loop through each item in Third Column of Table (displayed in Immediate Window [ctrl + g])
For x = LBound(myArray) To UBound(myArray)
Debug.Print myArray(x, 3)
Next x
End Sub