tradeaccepted
New Member
- Joined
- Jun 11, 2013
- Messages
- 33
Hello,
I have a script that I found from KuTools that will help delete all columns that have no data, only a header.
The script runs pretty slow, but it does what I need so im ok with that.
I am trying to add something to this code where after the script is run, it will create a new sheet and that sheet will contain two columns.
The first column will display a list of all the columns that were deleted. The second column will display a list of all the columns that still exist.
Is this possible?
I have a script that I found from KuTools that will help delete all columns that have no data, only a header.
Code:
Sub RemoveEmptyFields()
Dim xEndCol As Long
Dim i As Long
Dim xDel As Boolean
On Error Resume Next
xEndCol = Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
If xEndCol = 0 Then
MsgBox "There is no data on """ & ActiveSheet.Name & """ .", vbExclamation, "Kutools for Excel"
Exit Sub
End If
Application.ScreenUpdating = False
For i = xEndCol To 1 Step -1
If Application.WorksheetFunction.CountA(Columns(i)) <= 1 Then
Columns(i).Delete
xDel = True
End If
Next
If xDel Then
MsgBox "All blank and column(s) with only a header row have now been deleted.", vbInformation, "Kutools for Excel"
Else
MsgBox "There are no Columns to delete as each one has more data (rows) than just a header.", vbExclamation, "Kutools for Excel"
End If
Application.ScreenUpdating = False
End Sub
The script runs pretty slow, but it does what I need so im ok with that.
I am trying to add something to this code where after the script is run, it will create a new sheet and that sheet will contain two columns.
- Columns Removed
- Columns Kept
The first column will display a list of all the columns that were deleted. The second column will display a list of all the columns that still exist.
Is this possible?