Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default 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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default 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






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting empty rows Felix New Users to Excel 1 February 3rd 09 07:48 AM
Deleting empty cells LiAD Excel Worksheet Functions 4 January 27th 09 12:59 PM
Deleting all empty raws and columns. SURCAL Excel Discussion (Misc queries) 6 February 6th 08 06:45 AM
Deleting All Empty Rows bodhisatvaofboogie Excel Discussion (Misc queries) 3 May 18th 06 12:36 PM
Deleting empty rows Foss Excel Programming 4 June 4th 04 07:41 AM


All times are GMT +1. The time now is 10:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"