LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #26   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default using Macro in excel spreed sheet

Tom:

This one even better, I really appreciated all your
effort.

Lillian
-----Original Message-----

And this will get the blank columns and will speed things

up minimally by
not having to count the number of cells in a column over

and over. Note
that if you have several blank columns at the left most

(such as A and B)
which are not in the UsedRange, these will be left

untouched. This is one
reason I used a different approach, but it is an unlikely

scenario.

Option Explicit
Sub testme03()
Dim myRng As Range
Dim delRng As Range
Dim myCol As Range
Dim wks As Worksheet
Dim cnt as Long

Set wks = Worksheets("sheet1")

With wks
Set myRng = .UsedRange
cnt = myRng.columns(1).Cells.count
For Each myCol In myRng.Columns
If Application.CountIf(myCol, 0) = cnt _
Or Application.CountIf(myCol, "na") = cnt _
Or Application.CountA(myCol) = 0 Then
If delRng Is Nothing Then
Set delRng = myCol.Cells(1)
Else
Set delRng = Union(myCol.Cells(1),

delRng)
End If
End If
Next myCol
End With

If delRng Is Nothing Then
'do nothing
Else
delRng.EntireColumn.Delete
End If
End Sub

--
Regards,
Tom Ogilvy



Dave Peterson wrote in message
...
I read your other post and this'll get both 0's and

NA's.

Option Explicit
Sub testme03()
Dim myRng As Range
Dim delRng As Range
Dim myCol As Range
Dim wks As Worksheet

Set wks = Worksheets("sheet1")

With wks
Set myRng = .UsedRange
For Each myCol In myRng.Columns
If Application.CountIf(myCol, 0) =

myCol.Cells.Count _
Or Application.CountIf(myCol, "na") =

myCol.Cells.Count Then
If delRng Is Nothing Then
Set delRng = myCol.Cells(1)
Else
Set delRng = Union(myCol.Cells(1),

delRng)
End If
End If
Next myCol
End With

If delRng Is Nothing Then
'do nothing
Else
delRng.EntireColumn.Delete
End If

End Sub

<<snipped

--

Dave Peterson



.

 
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
How do I draw chemical structures in Excel spreed sheet? James Charts and Charting in Excel 1 March 31st 09 08:29 AM
save a excel spreed sheet to a word document? allend27 Excel Discussion (Misc queries) 2 July 29th 08 12:44 PM
Formating Excel Spreed Sheet xkaylax Excel Discussion (Misc queries) 1 January 31st 08 01:43 AM
find last record in macro and delete all after Sherife Excel Discussion (Misc queries) 3 September 18th 06 03:51 AM
How can I read over than 65,536 rows from excel spreed sheet Lillian Excel Discussion (Misc queries) 2 April 16th 06 01:47 AM


All times are GMT +1. The time now is 04:55 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"