Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I am writing a Macro and wondering if there is away to delect a row if
cell b and cell c =0? |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Add/Delect Macro | Excel Worksheet Functions | |||
How do I view the maximum rows in Excel 2007 (Million Rows)? | Excel Discussion (Misc queries) | |||
Excel 2003 -Rows hidden. Scrolling unhides rows ! How do I stop th | Excel Discussion (Misc queries) | |||
Inserting multiple rows in excel with data in consecutive rows | Excel Programming | |||
Can Excel "slide up" rows with content thru empty rows to condense | Excel Worksheet Functions |