Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel VBA - Delete entire row if all values are 0

Hello,
I am new to VBA Programming. Here is what I am trying to do. I have
spreadsheet and I need to go through the spreadsheet columns J throug
W and if the cell values are all zeros then delete the entire row i
any one of the cells have a value of 1 then go to the next row.

Thank for any help you can provide.

Ton

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Excel VBA - Delete entire row if all values are 0

Hi Tony

Try this. It does assume that the data is in rows 2
downwards.


Tony

Sub aaa()
Range("j65536").End(xlUp).Select
While Not IsEmpty(ActiveCell)
If WorksheetFunction.Max(Range(ActiveCell,
ActiveCell.Offset(0, 13))) = 0 And WorksheetFunction.Min
(Range(ActiveCell, ActiveCell.Offset(0, 13))) = 0 Then
ActiveCell.EntireRow.Delete
End If
ActiveCell.Offset(-1, 0).Select
Wend

End Sub

-----Original Message-----
Hello,
I am new to VBA Programming. Here is what I am trying to

do. I have a
spreadsheet and I need to go through the spreadsheet

columns J through
W and if the cell values are all zeros then delete the

entire row if
any one of the cells have a value of 1 then go to the

next row.

Thank for any help you can provide.

Tony


---
Message posted from http://www.ExcelForum.com/

.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Excel VBA - Delete entire row if all values are 0

Hi Tony

The following code will do what you want - it runs down the spreadsheet
until it finds a blank cell in Col A and deletes any rows where the total in
J to W is 0.

HTH

David

##########################################

Sub macro1()
Dim x As Integer

x = 1

While (Range("A" & x).Value < "")
If (Application.WorksheetFunction.Sum(Range("J" & x & ":W" & x)) =
0) Then Rows(x & ":" & x).Delete: x = x - 1
x = x + 1
Wend
End Sub

##########################################

"afurlani " wrote in message
...
Hello,
I am new to VBA Programming. Here is what I am trying to do. I have a
spreadsheet and I need to go through the spreadsheet columns J through
W and if the cell values are all zeros then delete the entire row if
any one of the cells have a value of 1 then go to the next row.

Thank for any help you can provide.

Tony


---
Message posted from http://www.ExcelForum.com/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel VBA - Delete entire row if all values are 0

I have tried the below code and it deletes every row? I think this coul
be becasue the cells format is text not numeric? Do you think this i
what is happening because all rows get deleted.
Thanks for your help
Tony


Sub macro1()
Dim x As Integer

x = 1

While (Range("A" & x).Value < "")
If (Application.WorksheetFunction.Sum(Range("J" & x & ":W" & x)) =
0) Then Rows(x & ":" & x).Delete: x = x - 1
x = x + 1
Wend
End Su

--
Message posted from http://www.ExcelForum.com

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel VBA - Delete entire row if all values are 0

I changed the format to numeric and it still deletes every row in the
spreadsheet. Please help.
Thanks
Tony


---
Message posted from http://www.ExcelForum.com/



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Excel VBA - Delete entire row if all values are 0

Try this one

See this page also
http://www.rondebruin.nl/delete.htm

Sub Example1()
Dim Lrow As Long
Dim CalcMode As Long
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

With ActiveSheet
.DisplayPageBreaks = False
For Lrow = .UsedRange.Rows.Count To 1 Step -1
If Application.Sum(Range(.Cells(Lrow, "J"), .Cells(Lrow, "W"))) = 0 Then .Rows(Lrow).Delete
Next
End With
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"afurlani " wrote in message ...
I changed the format to numeric and it still deletes every row in the
spreadsheet. Please help.
Thanks
Tony


---
Message posted from http://www.ExcelForum.com/



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Excel VBA - Delete entire row if all values are 0

Hi Tony

Can't get it to fail for me....

Comment out the if line (put a ' at the start) and substitute this line:

msgbox(Application.WorksheetFunction.Sum(Range("J" & x & ":W" & x))

This will display a box for each line showing the total and thus let you
know what's happening - it could Excel is rounding or something similar...

Regards


David


"afurlani " wrote in message
...
I have tried the below code and it deletes every row? I think this could
be becasue the cells format is text not numeric? Do you think this is
what is happening because all rows get deleted.
Thanks for your help
Tony


Sub macro1()
Dim x As Integer

x = 1

While (Range("A" & x).Value < "")
If (Application.WorksheetFunction.Sum(Range("J" & x & ":W" & x)) =
0) Then Rows(x & ":" & x).Delete: x = x - 1
x = x + 1
Wend
End Sub


---
Message posted from http://www.ExcelForum.com/



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel VBA - Delete entire row if all values are 0

The code works great! Thanks. The problem is I have a macro the
imports a txt file into excell and I can change the cell format to
number and it still does not recognize it has being a number. If I
clear the cell and input a 0 or 1 it then works. It is really weird.
The spreadsheet still has a .txt extension on it because I have not
saved it to xls format. So I saved it to a XLS format and the fields
still are not recognized as number.

Thanks,
Tony


---
Message posted from http://www.ExcelForum.com/

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Excel VBA - Delete entire row if all values are 0

Hi Tony

If you mail me the txt file I'll have a play and see if I can figure out
what's going on for you:

david at digicon dot com dot au

Regards

David



"afurlani " wrote in message
...
The code works great! Thanks. The problem is I have a macro the
imports a txt file into excell and I can change the cell format to
number and it still does not recognize it has being a number. If I
clear the cell and input a 0 or 1 it then works. It is really weird.
The spreadsheet still has a .txt extension on it because I have not
saved it to xls format. So I saved it to a XLS format and the fields
still are not recognized as number.

Thanks,
Tony


---
Message posted from http://www.ExcelForum.com/



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
How do I delete an entire document in excel 2007? meghan New Users to Excel 2 February 1st 10 03:43 PM
Macro to copy values then delete row for entire sheet Pyrotoy New Users to Excel 18 December 9th 08 12:43 AM
Delete an entire row One-Leg Excel Discussion (Misc queries) 13 November 11th 08 08:27 PM
Delete entire row if David T Excel Discussion (Misc queries) 2 December 6th 06 10:14 PM
How do I delete duplicate records from an entire Excel workbook? Steven B. Excel Discussion (Misc queries) 0 December 6th 05 10:32 AM


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

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"