I have a table that has many columns (includes autofiltered headers) and some of the columns have just the header with no other data following withink that column. I want to remove those columns from my named table.
Asked
Active
Viewed 351 times
-1
-
1What have you tried so far? – Michael Murphy Apr 22 '19 at 19:18
2 Answers
1
To delete a column, select the entire column of the spreadsheet. Then right click with the mouse on the selected column, and select "Delete".
Note that pressing Delete on the keyboard will only delete the content and not remove the column completely.
Be careful, this method removes the entire column of the spreadsheet so the data under the table will be effected as well.

Grigory Ilizirov
- 1,030
- 1
- 8
- 26
0
here is the code for you , next time try to code something
Public Sub teste()
Call DeleteTableColumnNull("table")
End Sub
Public Sub DeleteTableColumnNull(ByVal TableObjectName As String)
Dim table As ListObject
Dim st As Worksheet
Dim cols As Range
Dim col As Range
Dim rows As Range
Dim row As Range
For Each st In ThisWorkbook.Worksheets
If tableExistInThisSheet(st, TableObjectName) Then
Set table = st.ListObjects(TableObjectName)
For Each col In table.Range.Columns
If Application.WorksheetFunction.CountA(col) = 1 Then
col.Delete
End If
Next col
End If
Next
End Sub
Public Function tableExistInThisSheet(st As Worksheet, TableObjectName As String) As Boolean
On Error GoTo f
Dim tb As ListObject
Set tb = st.ListObjects(TableObjectName)
tableExistInThisSheet = True
Exit Function
f:
End Function

Ronan Vico
- 585
- 3
- 9
-
Yes, Ronan I have been using code to try and remove my "null" columns and nothing seems to work. I have only been coding for a couple of months so I know it's something that I need to learn. I tried your code but it doesn't and I don't get any errors. Suggestions? – teenyla Apr 26 '19 at 19:20
-
Null is differente them Blank Cells , i am using CountA do count if there is no cells Blank = "" , If is = "NULL" it wont work – Ronan Vico Apr 28 '19 at 23:42