Senso
Inventaris
- Lid geworden
- 13 jun 2016
- Berichten
- 12.143
- Besturingssysteem
- W11 Pro 25H2
- Office versie
- Office 2007 H&S en Office 2021 Prof Plus
Ik heb Google contacten geïmporteerd in Excel 2021 gegevens ophalen tekst uit csv dan maakt die er een tabel van wat ik liever niet wil. Nu wil ik lege kolommen deleten, dat lukt niet. Hoe moet dit wel?
PHP:
Sub DeleteEmptyColumns()
Dim ws As Worksheet
Dim lastCol As Long
Dim i As Long
' Optimize performance
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Set ws = ActiveSheet
' Find the last column that contains data or formatting
lastCol = ws.UsedRange.Columns.Count + ws.UsedRange.Column - 1
' Loop backwards from the last column to the first column
For i = lastCol To 1 Step -1
' Check if the column is completely empty using COUNTA
If Application.WorksheetFunction.CountA(ws.Columns(i)) = 0 Then
ws.Columns(i).Delete
End If
Next i
' Restore settings
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
MsgBox "All empty columns have been successfully deleted!", vbInformation
End Sub