Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default easy script for deleting blank columns

Hi, I liked Ron De Bruin's script for deleting blank rows. It worked. I have
tried to also modified it to delete blank columns. This is what I have:
Dim Lcol As Long
Dim CalcMode As Long
Dim ViewMode As Long
Dim Startcol As Long
Dim Endcol As Long

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView

With ActiveSheet
.DisplayPageBreaks = False
Startcol = 1
Endcol = 25

For Lcol = Endcol To Startcol Step -1

If Application.CountA(.cols(Lcol)) = 0 Then .cols(Lcol).Delete
'This will delete the column if the whole column is empty (all
rows)

Next
End With

ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With

End Sub

Not knowing lots about visual basic, I have been finding and modifying
script without a deep understanding of the various areas which is obviously
why this isn't working for me. I have a problem with "If
Application.CountA(.cols(Lcol)) = 0 Then .cols(Lcol).Delete" line but I guess
I might have other issues out there I am yet to discover.

Am I on the right track here? Can anyone help with this??
Cheers
Gai

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default easy script for deleting blank columns

You were close:

If Application.CountA(.Columns(Lcol)) = 0 Then .Columns(Lcol).Delete

You abbreviated .columns with .cols. That was a deal breaker!

After that change, the code worked ok for me.

GaiGauci wrote:

Hi, I liked Ron De Bruin's script for deleting blank rows. It worked. I have
tried to also modified it to delete blank columns. This is what I have:
Dim Lcol As Long
Dim CalcMode As Long
Dim ViewMode As Long
Dim Startcol As Long
Dim Endcol As Long

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView

With ActiveSheet
.DisplayPageBreaks = False
Startcol = 1
Endcol = 25

For Lcol = Endcol To Startcol Step -1

If Application.CountA(.cols(Lcol)) = 0 Then .cols(Lcol).Delete
'This will delete the column if the whole column is empty (all
rows)

Next
End With

ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With

End Sub

Not knowing lots about visual basic, I have been finding and modifying
script without a deep understanding of the various areas which is obviously
why this isn't working for me. I have a problem with "If
Application.CountA(.cols(Lcol)) = 0 Then .cols(Lcol).Delete" line but I guess
I might have other issues out there I am yet to discover.

Am I on the right track here? Can anyone help with this??
Cheers
Gai


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default easy script for deleting blank columns

Hi,


use .columns(lcol) and not .cols(lcol)

Sam

"GaiGauci" wrote:

Hi, I liked Ron De Bruin's script for deleting blank rows. It worked. I have
tried to also modified it to delete blank columns. This is what I have:
Dim Lcol As Long
Dim CalcMode As Long
Dim ViewMode As Long
Dim Startcol As Long
Dim Endcol As Long

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView

With ActiveSheet
.DisplayPageBreaks = False
Startcol = 1
Endcol = 25

For Lcol = Endcol To Startcol Step -1

If Application.CountA(.cols(Lcol)) = 0 Then .cols(Lcol).Delete
'This will delete the column if the whole column is empty (all
rows)

Next
End With

ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With

End Sub

Not knowing lots about visual basic, I have been finding and modifying
script without a deep understanding of the various areas which is obviously
why this isn't working for me. I have a problem with "If
Application.CountA(.cols(Lcol)) = 0 Then .cols(Lcol).Delete" line but I guess
I might have other issues out there I am yet to discover.

Am I on the right track here? Can anyone help with this??
Cheers
Gai

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default easy script for deleting blank columns

Thanks to both Sam and David. Just learning script and I think I make it up
as I go!

Thanks again for your input.

Cheers
Gai

"GaiGauci" wrote:

Hi, I liked Ron De Bruin's script for deleting blank rows. It worked. I have
tried to also modified it to delete blank columns. This is what I have:
Dim Lcol As Long
Dim CalcMode As Long
Dim ViewMode As Long
Dim Startcol As Long
Dim Endcol As Long

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView

With ActiveSheet
.DisplayPageBreaks = False
Startcol = 1
Endcol = 25

For Lcol = Endcol To Startcol Step -1

If Application.CountA(.cols(Lcol)) = 0 Then .cols(Lcol).Delete
'This will delete the column if the whole column is empty (all
rows)

Next
End With

ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With

End Sub

Not knowing lots about visual basic, I have been finding and modifying
script without a deep understanding of the various areas which is obviously
why this isn't working for me. I have a problem with "If
Application.CountA(.cols(Lcol)) = 0 Then .cols(Lcol).Delete" line but I guess
I might have other issues out there I am yet to discover.

Am I on the right track here? Can anyone help with this??
Cheers
Gai

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
reduce excel file size by deleting blank rows and columns?? Delta007bhd Excel Discussion (Misc queries) 5 April 4th 23 12:48 PM
Deleting blank cells w/o impacting other rows/columns ShagNasty Excel Programming 5 October 26th 08 04:34 PM
Newbee - deleting blank columns Rednosebob Excel Programming 5 March 29th 06 03:55 AM
OsCommerce - Easy Populate Script - CSV/TXT Conversion Problem. PriceTrim Excel Discussion (Misc queries) 3 July 5th 05 05:27 PM
deleting text is easy... but what about this?!!! ian123[_5_] Excel Programming 2 December 7th 03 06:45 PM


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

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

About Us

"It's about Microsoft Excel"