Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default help with macro


Need help with a simple excel macro
What I need it to do is :
if a cell in column B=has the work "No" in it and the cell in column C that
is next to it is blank or empty the row needs to be deleted

Thanks
Bob
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default help with macro


copy this code to a standard module:=

Sub demo()
dim cell as range
for each cell in Range("B:B").Cells
if cell.value = "No" AND cell.Offset(,1)="" then
Rows(cell.Row).Delete
end if
next
End Sub

OPen the development environment, ALT+F11
Add a module - from the INSERT menu select MODULE



"Bobbo" wrote in message
...
Need help with a simple excel macro
What I need it to do is :
if a cell in column B=has the work "No" in it and the cell in column C
that
is next to it is blank or empty the row needs to be deleted

Thanks
Bob


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default help with macro


That could cause trouble.

It's usually better to delete rows starting from the bottom up.

Option Explicit
Sub Testme()
dim LastRow as long
dim FirstRow as long
dim iRow as long

with worksheets("sheet99999") 'activesheet???
firstrow = 2 'headers in row 1????
lastrow = .cells(.rows.count,"A").end(xlup).row
for irow = lastrow to firstrow step -1
if lcase(.cells(irow,"B").value) = lcase("no") then
if .cells(irow,"C").value = "" then
.rows(irow).delete
end if
end if
next irow
end with
end sub

======
But if the OP wants to work from the top toward the bottom:

Option Explicit
Sub Testme2()
Dim myCell As Range
Dim myRng As Range
Dim DelRng As Range

with worksheets("sheet99999") 'activesheet???
Set myRng = .Range("B2", .Cells(.Rows.Count, "B").End(xlUp))
End With

For Each myCell In myRng.Cells
If LCase(myCell.Value) = LCase("no") Then
If myCell.Offset(0, 1).Value = "" Then
If DelRng Is Nothing Then
Set DelRng = myCell
Else
Set DelRng = Union(DelRng, myCell)
End If
End If
End If
Next myCell

If DelRng Is Nothing Then
'do nothing
Else
DelRng.EntireRow.Delete
End If

End Sub



Patrick Molloy wrote:

copy this code to a standard module:=

Sub demo()
dim cell as range
for each cell in Range("B:B").Cells
if cell.value = "No" AND cell.Offset(,1)="" then
Rows(cell.Row).Delete
end if
next
End Sub

OPen the development environment, ALT+F11
Add a module - from the INSERT menu select MODULE

"Bobbo" wrote in message
...
Need help with a simple excel macro
What I need it to do is :
if a cell in column B=has the work "No" in it and the cell in column C
that
is next to it is blank or empty the row needs to be deleted

Thanks
Bob


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default help with macro


Thanks,
It works but I have to run it more than once to get all rows removed.
Any suggestions

"Patrick Molloy" wrote:

copy this code to a standard module:=

Sub demo()
dim cell as range
for each cell in Range("B:B").Cells
if cell.value = "No" AND cell.Offset(,1)="" then
Rows(cell.Row).Delete
end if
next
End Sub

OPen the development environment, ALT+F11
Add a module - from the INSERT menu select MODULE



"Bobbo" wrote in message
...
Need help with a simple excel macro
What I need it to do is :
if a cell in column B=has the work "No" in it and the cell in column C
that
is next to it is blank or empty the row needs to be deleted

Thanks
Bob



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default help with macro


Or, with this slightly shorter routine, as you come to them...

Sub DeleteNoBlankCombo()
On Error GoTo NoMore
Do
ActiveSheet.Range("B:B").Find(What:="No", LookAt:=xlWhole, _
LookIn:=xlValues, MatchCase:="False").EntireRow.Delete
Loop
NoMo
End Sub

Where the OP can specify an specific worksheet reference in place of the
ActiveSheet one that I used.

--
Rick (MVP - Excel)


"Dave Peterson" wrote in message
...
That could cause trouble.

It's usually better to delete rows starting from the bottom up.

Option Explicit
Sub Testme()
dim LastRow as long
dim FirstRow as long
dim iRow as long

with worksheets("sheet99999") 'activesheet???
firstrow = 2 'headers in row 1????
lastrow = .cells(.rows.count,"A").end(xlup).row
for irow = lastrow to firstrow step -1
if lcase(.cells(irow,"B").value) = lcase("no") then
if .cells(irow,"C").value = "" then
.rows(irow).delete
end if
end if
next irow
end with
end sub

======
But if the OP wants to work from the top toward the bottom:

Option Explicit
Sub Testme2()
Dim myCell As Range
Dim myRng As Range
Dim DelRng As Range

with worksheets("sheet99999") 'activesheet???
Set myRng = .Range("B2", .Cells(.Rows.Count, "B").End(xlUp))
End With

For Each myCell In myRng.Cells
If LCase(myCell.Value) = LCase("no") Then
If myCell.Offset(0, 1).Value = "" Then
If DelRng Is Nothing Then
Set DelRng = myCell
Else
Set DelRng = Union(DelRng, myCell)
End If
End If
End If
Next myCell

If DelRng Is Nothing Then
'do nothing
Else
DelRng.EntireRow.Delete
End If

End Sub



Patrick Molloy wrote:

copy this code to a standard module:=

Sub demo()
dim cell as range
for each cell in Range("B:B").Cells
if cell.value = "No" AND cell.Offset(,1)="" then
Rows(cell.Row).Delete
end if
next
End Sub

OPen the development environment, ALT+F11
Add a module - from the INSERT menu select MODULE

"Bobbo" wrote in message
...
Need help with a simple excel macro
What I need it to do is :
if a cell in column B=has the work "No" in it and the cell in column C
that
is next to it is blank or empty the row needs to be deleted

Thanks
Bob


--

Dave Peterson




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default help with macro


for rw = range("B65000").End(xlUp).Row to 1 step -1
if cells(rw,"B")="No" then
if cells(rw,"C")="" then
rows(rw).delete
End if
end if
next

"Bobbo" wrote in message
...
Thanks,
It works but I have to run it more than once to get all rows removed.
Any suggestions

"Patrick Molloy" wrote:

copy this code to a standard module:=

Sub demo()
dim cell as range
for each cell in Range("B:B").Cells
if cell.value = "No" AND cell.Offset(,1)="" then
Rows(cell.Row).Delete
end if
next
End Sub

OPen the development environment, ALT+F11
Add a module - from the INSERT menu select MODULE



"Bobbo" wrote in message
...
Need help with a simple excel macro
What I need it to do is :
if a cell in column B=has the work "No" in it and the cell in column C
that
is next to it is blank or empty the row needs to be deleted

Thanks
Bob



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default help with macro


I think you missed that portion about column C being empty at the same time.

Rick Rothstein wrote:

Or, with this slightly shorter routine, as you come to them...

Sub DeleteNoBlankCombo()
On Error GoTo NoMore
Do
ActiveSheet.Range("B:B").Find(What:="No", LookAt:=xlWhole, _
LookIn:=xlValues, MatchCase:="False").EntireRow.Delete
Loop
NoMo
End Sub

Where the OP can specify an specific worksheet reference in place of the
ActiveSheet one that I used.

--
Rick (MVP - Excel)

"Dave Peterson" wrote in message
...
That could cause trouble.

It's usually better to delete rows starting from the bottom up.

Option Explicit
Sub Testme()
dim LastRow as long
dim FirstRow as long
dim iRow as long

with worksheets("sheet99999") 'activesheet???
firstrow = 2 'headers in row 1????
lastrow = .cells(.rows.count,"A").end(xlup).row
for irow = lastrow to firstrow step -1
if lcase(.cells(irow,"B").value) = lcase("no") then
if .cells(irow,"C").value = "" then
.rows(irow).delete
end if
end if
next irow
end with
end sub

======
But if the OP wants to work from the top toward the bottom:

Option Explicit
Sub Testme2()
Dim myCell As Range
Dim myRng As Range
Dim DelRng As Range

with worksheets("sheet99999") 'activesheet???
Set myRng = .Range("B2", .Cells(.Rows.Count, "B").End(xlUp))
End With

For Each myCell In myRng.Cells
If LCase(myCell.Value) = LCase("no") Then
If myCell.Offset(0, 1).Value = "" Then
If DelRng Is Nothing Then
Set DelRng = myCell
Else
Set DelRng = Union(DelRng, myCell)
End If
End If
End If
Next myCell

If DelRng Is Nothing Then
'do nothing
Else
DelRng.EntireRow.Delete
End If

End Sub



Patrick Molloy wrote:

copy this code to a standard module:=

Sub demo()
dim cell as range
for each cell in Range("B:B").Cells
if cell.value = "No" AND cell.Offset(,1)="" then
Rows(cell.Row).Delete
end if
next
End Sub

OPen the development environment, ALT+F11
Add a module - from the INSERT menu select MODULE

"Bobbo" wrote in message
...
Need help with a simple excel macro
What I need it to do is :
if a cell in column B=has the work "No" in it and the cell in column C
that
is next to it is blank or empty the row needs to be deleted

Thanks
Bob


--

Dave Peterson


--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default help with macro


<gulp I sure did!

--
Rick (MVP - Excel)


"Dave Peterson" wrote in message
...
I think you missed that portion about column C being empty at the same
time.

Rick Rothstein wrote:

Or, with this slightly shorter routine, as you come to them...

Sub DeleteNoBlankCombo()
On Error GoTo NoMore
Do
ActiveSheet.Range("B:B").Find(What:="No", LookAt:=xlWhole, _
LookIn:=xlValues, MatchCase:="False").EntireRow.Delete
Loop
NoMo
End Sub

Where the OP can specify an specific worksheet reference in place of the
ActiveSheet one that I used.

--
Rick (MVP - Excel)

"Dave Peterson" wrote in message
...
That could cause trouble.

It's usually better to delete rows starting from the bottom up.

Option Explicit
Sub Testme()
dim LastRow as long
dim FirstRow as long
dim iRow as long

with worksheets("sheet99999") 'activesheet???
firstrow = 2 'headers in row 1????
lastrow = .cells(.rows.count,"A").end(xlup).row
for irow = lastrow to firstrow step -1
if lcase(.cells(irow,"B").value) = lcase("no") then
if .cells(irow,"C").value = "" then
.rows(irow).delete
end if
end if
next irow
end with
end sub

======
But if the OP wants to work from the top toward the bottom:

Option Explicit
Sub Testme2()
Dim myCell As Range
Dim myRng As Range
Dim DelRng As Range

with worksheets("sheet99999") 'activesheet???
Set myRng = .Range("B2", .Cells(.Rows.Count, "B").End(xlUp))
End With

For Each myCell In myRng.Cells
If LCase(myCell.Value) = LCase("no") Then
If myCell.Offset(0, 1).Value = "" Then
If DelRng Is Nothing Then
Set DelRng = myCell
Else
Set DelRng = Union(DelRng, myCell)
End If
End If
End If
Next myCell

If DelRng Is Nothing Then
'do nothing
Else
DelRng.EntireRow.Delete
End If

End Sub



Patrick Molloy wrote:

copy this code to a standard module:=

Sub demo()
dim cell as range
for each cell in Range("B:B").Cells
if cell.value = "No" AND cell.Offset(,1)="" then
Rows(cell.Row).Delete
end if
next
End Sub

OPen the development environment, ALT+F11
Add a module - from the INSERT menu select MODULE

"Bobbo" wrote in message
...
Need help with a simple excel macro
What I need it to do is :
if a cell in column B=has the work "No" in it and the cell in column
C
that
is next to it is blank or empty the row needs to be deleted

Thanks
Bob

--

Dave Peterson


--

Dave Peterson


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default help with macro


Never happens to me -- Hey! Stop laughing!!!!

Rick Rothstein wrote:

<gulp I sure did!

--
Rick (MVP - Excel)

"Dave Peterson" wrote in message
...
I think you missed that portion about column C being empty at the same
time.

Rick Rothstein wrote:

Or, with this slightly shorter routine, as you come to them...

Sub DeleteNoBlankCombo()
On Error GoTo NoMore
Do
ActiveSheet.Range("B:B").Find(What:="No", LookAt:=xlWhole, _
LookIn:=xlValues, MatchCase:="False").EntireRow.Delete
Loop
NoMo
End Sub

Where the OP can specify an specific worksheet reference in place of the
ActiveSheet one that I used.

--
Rick (MVP - Excel)

"Dave Peterson" wrote in message
...
That could cause trouble.

It's usually better to delete rows starting from the bottom up.

Option Explicit
Sub Testme()
dim LastRow as long
dim FirstRow as long
dim iRow as long

with worksheets("sheet99999") 'activesheet???
firstrow = 2 'headers in row 1????
lastrow = .cells(.rows.count,"A").end(xlup).row
for irow = lastrow to firstrow step -1
if lcase(.cells(irow,"B").value) = lcase("no") then
if .cells(irow,"C").value = "" then
.rows(irow).delete
end if
end if
next irow
end with
end sub

======
But if the OP wants to work from the top toward the bottom:

Option Explicit
Sub Testme2()
Dim myCell As Range
Dim myRng As Range
Dim DelRng As Range

with worksheets("sheet99999") 'activesheet???
Set myRng = .Range("B2", .Cells(.Rows.Count, "B").End(xlUp))
End With

For Each myCell In myRng.Cells
If LCase(myCell.Value) = LCase("no") Then
If myCell.Offset(0, 1).Value = "" Then
If DelRng Is Nothing Then
Set DelRng = myCell
Else
Set DelRng = Union(DelRng, myCell)
End If
End If
End If
Next myCell

If DelRng Is Nothing Then
'do nothing
Else
DelRng.EntireRow.Delete
End If

End Sub



Patrick Molloy wrote:

copy this code to a standard module:=

Sub demo()
dim cell as range
for each cell in Range("B:B").Cells
if cell.value = "No" AND cell.Offset(,1)="" then
Rows(cell.Row).Delete
end if
next
End Sub

OPen the development environment, ALT+F11
Add a module - from the INSERT menu select MODULE

"Bobbo" wrote in message
...
Need help with a simple excel macro
What I need it to do is :
if a cell in column B=has the work "No" in it and the cell in column
C
that
is next to it is blank or empty the row needs to be deleted

Thanks
Bob

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
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
Macro Help Needed - Excel 2007 - Print Macro with Auto Sort Gavin Excel Worksheet Functions 0 May 17th 07 01:20 PM
Macro not showing in Tools/Macro/Macros yet show up when I goto VBA editor [email protected] Excel Programming 2 March 30th 07 07:48 PM
Need syntax for RUNning a Word macro with an argument, called from an Excel macro Steve[_84_] Excel Programming 3 July 6th 06 07:42 PM
macro to delete entire rows when column A is blank ...a quick macro vikram Excel Programming 4 May 3rd 04 08:45 PM
Start Macro / Stop Macro / Restart Macro Pete[_13_] Excel Programming 2 November 21st 03 05:04 PM


All times are GMT +1. The time now is 06:17 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"