View Single Post
  #44   Report Post  
Posted to microsoft.public.excel.programming
Lillian[_5_] Lillian[_5_] is offline
external usenet poster
 
Posts: 47
Default using Macro in excel spreed sheet

Dave:

If I use my real data and it work, it wipe out O
column, if I use the test data it won't work, I don't
know why, as you said I hit-end, it went to last row, and
I look at format cell is general.
Thank you so much.

Lillian
-----Original Message-----
I used Tom's code (dated: Sat, 15 Nov 2003 20:27:36 -

0500) against your data and
it wiped out all the columns.

First guess why it didn't work for you: That code

expects 0's, NA's or empty
cells in row 1 to the last row of the worksheet. Hit

ctrl-end to see if that
lastrow is where you expected it.

Second guess: Are those 0's the results of

calculations? Could the be very
small numbers that look like 0's when they appear in the

worksheet (either via
the numberformat of the cell or by the width of the

column)?

Try clicking one of them and looking at the actual value

in the formula bar.





Lillian wrote:

Dave:

I test this macro and it only delete the NA but not

0,
any idea? example

A B C D E
0 NA 0 NA 0
0 NA 0 NA 0
0 NA 0 NA 0

after that 0 still there, thank you.

Lillian
-----Original 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

.


--

Dave Peterson

.