ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Deleting Empty Columns (https://www.excelbanter.com/excel-programming/320924-deleting-empty-columns.html)

Scott

Deleting Empty Columns
 
I'm trying to delete all columns within the used range that contain no data
all the way down. My code below works fine for doing rows, but I can't find
syntax to do the same on columns.

Any help?

Sub DeleteEmptyRows()
Dim LastRow As Long
Dim r As Long
LastRow = ActiveSheet.UsedRange.Row - 1 +
ActiveSheet.UsedRange.Rows.Count
Application.ScreenUpdating = False
For r = LastRow To 1 Step -1
If Application.WorksheetFunction.CountA(Rows(r)) = 0 _
Then Rows(r).Delete
Next r
End Sub



Tom Ogilvy

Deleting Empty Columns
 
Sub DeleteEmptyRows()
Dim LastCol As Long
Dim r As Long
LastCol = ActiveSheet.UsedRange.Column - 1 + _
ActiveSheet.UsedRange.Columns.Count
Application.ScreenUpdating = False
For r = LastCol To 1 Step -1
If Application.WorksheetFunction.CountA(Columns(r)) = 0 _
Then Columns(r).Delete
Next r
End Sub

Would be my guess.

--
Regards,
Tom Ogilvy

"scott" wrote in message
...
I'm trying to delete all columns within the used range that contain no

data
all the way down. My code below works fine for doing rows, but I can't

find
syntax to do the same on columns.

Any help?

Sub DeleteEmptyRows()
Dim LastRow As Long
Dim r As Long
LastRow = ActiveSheet.UsedRange.Row - 1 +
ActiveSheet.UsedRange.Rows.Count
Application.ScreenUpdating = False
For r = LastRow To 1 Step -1
If Application.WorksheetFunction.CountA(Rows(r)) = 0 _
Then Rows(r).Delete
Next r
End Sub





Scott

Deleting Empty Columns
 
that did it.

"Tom Ogilvy" wrote in message
...
Sub DeleteEmptyRows()
Dim LastCol As Long
Dim r As Long
LastCol = ActiveSheet.UsedRange.Column - 1 + _
ActiveSheet.UsedRange.Columns.Count
Application.ScreenUpdating = False
For r = LastCol To 1 Step -1
If Application.WorksheetFunction.CountA(Columns(r)) = 0 _
Then Columns(r).Delete
Next r
End Sub

Would be my guess.

--
Regards,
Tom Ogilvy

"scott" wrote in message
...
I'm trying to delete all columns within the used range that contain no

data
all the way down. My code below works fine for doing rows, but I can't

find
syntax to do the same on columns.

Any help?

Sub DeleteEmptyRows()
Dim LastRow As Long
Dim r As Long
LastRow = ActiveSheet.UsedRange.Row - 1 +
ActiveSheet.UsedRange.Rows.Count
Application.ScreenUpdating = False
For r = LastRow To 1 Step -1
If Application.WorksheetFunction.CountA(Rows(r)) = 0 _
Then Rows(r).Delete
Next r
End Sub








All times are GMT +1. The time now is 05:45 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com