View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Newbee - deleting blank columns

Backup before testing. This will work on the activesheet, change if necessary.

Sub test()
Dim rCol As Range
Dim RngToDelete As Range

For Each rCol In ActiveSheet.UsedRange.Columns
If Application.CountA(rCol) = 0 Then
If RngToDelete Is Nothing Then
Set RngToDelete = rCol
Else: Set RngToDelete = Union(RngToDelete, rCol)
End If
End If
Next rCol

If Not RngToDelete Is Nothing Then _
RngToDelete.EntireColumn.Delete

End Sub

"Rednosebob" wrote:

Excel 2000 - I have a spreadsheet that is laid out to have enough columns
formated for the maxium possible uaeage for this application. The number of
columns actually used will vary. I know the maximum columns used, but I need
a macro that will delete all blank columns.

Thanks in advance for your help!

Bob