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 fornual to delect rows

I am writing a Macro and wondering if there is away to delect a row if
cell b and cell c =0?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Excel fornual to delect rows

you don't share a whole lot about what you want to do. try one of these:

Option Explicit

Sub test()
Dim ws As Worksheet
Set ws = Worksheets("sheet1")

With ws
If Cells(ActiveCell.Row, "B") = 0 And Cells(ActiveCell.Row, "B") = 0 Then
MsgBox "both = 0"
End If
End With

End Sub
Sub test2()
Dim ws As Worksheet
Set ws = Worksheets("sheet1")
Dim lastrow As Long
Dim cell As Range
lastrow = ws.Cells(Rows.Count, "B").End(xlUp).Row

With ws
For Each cell In .Range("B1:B" & lastrow)
If Application.Sum(cell.Resize(1, 2)) = 0 Then
MsgBox "row " & cell.Row & " both are 0"
End If

Next
End With

End Sub

--


Gary


wrote in message
oups.com...
I am writing a Macro and wondering if there is away to delect a row if
cell b and cell c =0?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default Excel fornual to delect rows

Just be aware that in your sub test2() below that if one cell is 6, and the
other -6 it will still say both are zero.

Also, if by 'delete' the original poster meant just to clear the contents,
with a line such as:
cell.EntireRow.ClearContents
to replace the msgbox line, then the macro will work as required.

If instead, the OP wanted to remove the row and close up the gap with
cell.EntireRow.Delete
then if there are two rows next to each other which need deleting, it will
miss the second one, because it runs from the top downwards.

So to be constructive, try it with these small adjustments

Sub test2()
Dim ws As Worksheet
Set ws = Worksheets("sheet1")
Dim lastrow As Long
Dim cell As Range
Dim i As Integer
lastrow = ws.Cells(Rows.Count, "B").End(xlUp).Row

With ws.Range("B1:B" & lastrow)
For i = .Cells.Count To 1 Step -1
If .Cells(i) = 0 And .Cells(i).Offset(0, 1) = 0 Then
MsgBox "row " & .Cells(i).Row & ", cells B and C are both 0"
.Cells(i).EntireRow.Delete
End If
Next i
End With

End Sub


--
p45cal


"Gary Keramidas" wrote:

you don't share a whole lot about what you want to do. try one of these:

Option Explicit

Sub test()
Dim ws As Worksheet
Set ws = Worksheets("sheet1")

With ws
If Cells(ActiveCell.Row, "B") = 0 And Cells(ActiveCell.Row, "B") = 0 Then
MsgBox "both = 0"
End If
End With

End Sub
Sub test2()
Dim ws As Worksheet
Set ws = Worksheets("sheet1")
Dim lastrow As Long
Dim cell As Range
lastrow = ws.Cells(Rows.Count, "B").End(xlUp).Row

With ws
For Each cell In .Range("B1:B" & lastrow)
If Application.Sum(cell.Resize(1, 2)) = 0 Then
MsgBox "row " & cell.Row & " both are 0"
End If

Next
End With

End Sub

--


Gary


wrote in message
oups.com...
I am writing a Macro and wondering if there is away to delect a row if
cell b and cell c =0?




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
Add/Delect Macro Chris Excel Worksheet Functions 1 September 18th 07 10:36 PM
How do I view the maximum rows in Excel 2007 (Million Rows)? shanth Excel Discussion (Misc queries) 2 January 15th 07 05:45 PM
Excel 2003 -Rows hidden. Scrolling unhides rows ! How do I stop th Excellent1975 Excel Discussion (Misc queries) 0 June 21st 06 08:01 PM
Inserting multiple rows in excel with data in consecutive rows technotronic Excel Programming 2 October 20th 05 03:12 PM
Can Excel "slide up" rows with content thru empty rows to condense portly44 Excel Worksheet Functions 2 April 1st 05 12:47 AM


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