OaklandJim
Well-known Member
- Joined
- Nov 29, 2018
- Messages
- 855
- Office Version
- 365
- Platform
- Windows
I am looping through tables in a worksheet named Sheet1. But for some reason Excel adds digits to the end of names in the loop.
Tables are used to record expenses. Table names are Transportation, Accommodations, Activities and Meals.
Code below generates the following Debug.Print output
Table name = Transportation812
Table name = Accommodations913
Table name = Activities1014
Table name = Meals1115
Tables are used to record expenses. Table names are Transportation, Accommodations, Activities and Meals.
Code below generates the following Debug.Print output
Table name = Transportation812
Table name = Accommodations913
Table name = Activities1014
Table name = Meals1115
VBA Code:
Sub DeleteEmptyTableRows()
Dim wsExpenses As Worksheet
Dim tDataTable As ListObject
Dim iTableRow As Long
Dim iDateColumn As Long
Dim avDataArray() As Variant
Set wsExpenses = Worksheets("Sheet1") '<= change this if the Expenses worksheet name changes
iDateColumn = 2 '<= change this if the date column number changes
For Each tDataTable In wsExpenses.ListObjects
With tDataTable
Debug.Print "Table name = " & .Name
' Only process specific tables in the Expenses worksheet.
If .Name = "Transportation" Or _
.Name = "Accommodations" Or _
.Name = "Activities" Or _
.Name = "Meals" _
Then
' Put table contents into an array.
avDataArray = .DataBodyRange
' Loop through each item in Date Column of Table
For iTableRow = LBound(avDataArray) To UBound(avDataArray)
If avDataArray(iTableRow, iDateColumn) = "" _
Then
'.ListRows(iTableRow).Delete
End If
Next iTableRow
End If
End With
Next tDataTable
End Sub