Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Deleting a row containing a found cell

After finding a cell using "Find", how do I delete the
entire row?

Regards,
Alan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Deleting a row containing a found cell

Hi
if you have assignet the found cell to a range object use something
like
found_cell.entirerow.delete

--
Regards
Frank Kabel
Frankfurt, Germany

"Alan" schrieb im Newsbeitrag
...
After finding a cell using "Find", how do I delete the
entire row?

Regards,
Alan


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Deleting a row containing a found cell

Alan,

Try something like

Dim FoundCell As Range
Set FoundCell = Cells.Find(....)
If Not FoundCell Is Nothing Then
FoundCell.EntireRow.Delete
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Alan" wrote in message
...
After finding a cell using "Find", how do I delete the
entire row?

Regards,
Alan



  #4   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Deleting a row containing a found cell

Chip,

Your code works fine when I execute it once.

If I create a Do loop, the code works only once if I don't
have the commented line.

Why do I need the commented line?

Thanks for your help.

Regards,
Alan


--------
Sub DeleteNARows()
Dim FoundCell As Range
Set FoundCell = Cells.Find("N/A")
Do While Not (FoundCell Is Nothing)
Set FoundCell = Cells.Find("N/A") 'Why needed?
FoundCell.EntireRow.Delete
Loop
End Sub
------------





-----Original Message-----
Alan,

Try something like

Dim FoundCell As Range
Set FoundCell = Cells.Find(....)
If Not FoundCell Is Nothing Then
FoundCell.EntireRow.Delete
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Alan" wrote in

message
...
After finding a cell using "Find", how do I delete the
entire row?

Regards,
Alan



.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Deleting a row containing a found cell

Chip's code works fine if you're only deleting the first instance:

Dim FoundCell As Range
Set FoundCell = Cells.Find(....)
If Not FoundCell Is Nothing Then
FoundCell.EntireRow.Delete
End If

But if you try to wrap it into a do loop like:

Dim FoundCell As Range
Set FoundCell = Cells.Find(....)
do while not (foundcell is nothing)
If Not FoundCell Is Nothing Then
FoundCell.EntireRow.Delete
End If
loop

The first time through the code, Foundcell will represent the first found cell.
But when you delete that row, then FoundCell doesn't point at anything. You
have to tell it to go find another cell.

So your extra "set FoundCell" finds that next cell.

I like this better (but it's personal preference for the most part):

Option Explicit

Sub DeleteNARows2()
Dim FoundCell As Range
Do
Set FoundCell = Cells.Find("N/A", LookIn:=xlFormulas, _
lookat:=xlPart, MatchCase:=False)
If FoundCell Is Nothing Then
Exit Do
Else
FoundCell.EntireRow.Delete
End If
Loop
End Sub

I don't have the extra "set foundcell" outside the loop.

But watch out for the .find stuff. Excel likes to remember the last settings
you've used. And if you don't explicitly set them the way you want, those last
settings will be used.



wrote:

Chip,

Your code works fine when I execute it once.

If I create a Do loop, the code works only once if I don't
have the commented line.

Why do I need the commented line?

Thanks for your help.

Regards,
Alan

--------
Sub DeleteNARows()
Dim FoundCell As Range
Set FoundCell = Cells.Find("N/A")
Do While Not (FoundCell Is Nothing)
Set FoundCell = Cells.Find("N/A") 'Why needed?
FoundCell.EntireRow.Delete
Loop
End Sub
------------

-----Original Message-----
Alan,

Try something like

Dim FoundCell As Range
Set FoundCell = Cells.Find(....)
If Not FoundCell Is Nothing Then
FoundCell.EntireRow.Delete
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Alan" wrote in

message
...
After finding a cell using "Find", how do I delete the
entire row?

Regards,
Alan



.


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Deleting a row containing a found cell

Or you could've changed the order in your modified code:

Sub DeleteNARows3()
Dim FoundCell As Range
Set FoundCell = Cells.Find("N/A")
Do While Not (FoundCell Is Nothing)
FoundCell.EntireRow.Delete
Set FoundCell = Cells.Find("N/A")
Loop
End Sub

(Find the next after you've deleted the previous. But I'd still stick in all
those .find options.)



Dave Peterson wrote:

Chip's code works fine if you're only deleting the first instance:

Dim FoundCell As Range
Set FoundCell = Cells.Find(....)
If Not FoundCell Is Nothing Then
FoundCell.EntireRow.Delete
End If

But if you try to wrap it into a do loop like:

Dim FoundCell As Range
Set FoundCell = Cells.Find(....)
do while not (foundcell is nothing)
If Not FoundCell Is Nothing Then
FoundCell.EntireRow.Delete
End If
loop

The first time through the code, Foundcell will represent the first found cell.
But when you delete that row, then FoundCell doesn't point at anything. You
have to tell it to go find another cell.

So your extra "set FoundCell" finds that next cell.

I like this better (but it's personal preference for the most part):

Option Explicit

Sub DeleteNARows2()
Dim FoundCell As Range
Do
Set FoundCell = Cells.Find("N/A", LookIn:=xlFormulas, _
lookat:=xlPart, MatchCase:=False)
If FoundCell Is Nothing Then
Exit Do
Else
FoundCell.EntireRow.Delete
End If
Loop
End Sub

I don't have the extra "set foundcell" outside the loop.

But watch out for the .find stuff. Excel likes to remember the last settings
you've used. And if you don't explicitly set them the way you want, those last
settings will be used.

wrote:

Chip,

Your code works fine when I execute it once.

If I create a Do loop, the code works only once if I don't
have the commented line.

Why do I need the commented line?

Thanks for your help.

Regards,
Alan

--------
Sub DeleteNARows()
Dim FoundCell As Range
Set FoundCell = Cells.Find("N/A")
Do While Not (FoundCell Is Nothing)
Set FoundCell = Cells.Find("N/A") 'Why needed?
FoundCell.EntireRow.Delete
Loop
End Sub
------------

-----Original Message-----
Alan,

Try something like

Dim FoundCell As Range
Set FoundCell = Cells.Find(....)
If Not FoundCell Is Nothing Then
FoundCell.EntireRow.Delete
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Alan" wrote in

message
...
After finding a cell using "Find", how do I delete the
entire row?

Regards,
Alan


.


--

Dave Peterson


--

Dave Peterson

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Deleting a row containing a found cell

But when you delete that row, then FoundCell doesn't
point at anything. You
have to tell it to go find another cell.


You're right! I've been deleting objects for years, in
Access and Word. But this is the first time that I've
actually deleted a real-world, live object that I can
watch being deleted :-)

The books always say that objects should be from the "real
world", but in fact most objects only live in system
memory. So deleting them usually means "Set BillGates =
Nothing". (This doesn't work :-)
-------------

But watch out for the .find stuff. Excel likes to

remember the last settings
you've used. And if you don't explicitly set them the

way you want, those last
settings will be used.


Since I'm new to Excel programming, that didn't occur to
me. But exactly the same thing happens in Word.
-------------

Thanks for your help.

Regards,
Alan



-----Original Message-----
Or you could've changed the order in your modified code:

Sub DeleteNARows3()
Dim FoundCell As Range
Set FoundCell = Cells.Find("N/A")
Do While Not (FoundCell Is Nothing)
FoundCell.EntireRow.Delete
Set FoundCell = Cells.Find("N/A")
Loop
End Sub

(Find the next after you've deleted the previous. But

I'd still stick in all
those .find options.)



Dave Peterson wrote:

Chip's code works fine if you're only deleting the

first instance:

Dim FoundCell As Range
Set FoundCell = Cells.Find(....)
If Not FoundCell Is Nothing Then
FoundCell.EntireRow.Delete
End If

But if you try to wrap it into a do loop like:

Dim FoundCell As Range
Set FoundCell = Cells.Find(....)
do while not (foundcell is nothing)
If Not FoundCell Is Nothing Then
FoundCell.EntireRow.Delete
End If
loop

The first time through the code, Foundcell will

represent the first found cell.
But when you delete that row, then FoundCell doesn't

point at anything. You
have to tell it to go find another cell.

So your extra "set FoundCell" finds that next cell.

I like this better (but it's personal preference for

the most part):

Option Explicit

Sub DeleteNARows2()
Dim FoundCell As Range
Do
Set FoundCell = Cells.Find("N/A",

LookIn:=xlFormulas, _
lookat:=xlPart,

MatchCase:=False)
If FoundCell Is Nothing Then
Exit Do
Else
FoundCell.EntireRow.Delete
End If
Loop
End Sub

I don't have the extra "set foundcell" outside the loop.

But watch out for the .find stuff. Excel likes to

remember the last settings
you've used. And if you don't explicitly set them the

way you want, those last
settings will be used.

wrote:

Chip,

Your code works fine when I execute it once.

If I create a Do loop, the code works only once if I

don't
have the commented line.

Why do I need the commented line?

Thanks for your help.

Regards,
Alan

--------
Sub DeleteNARows()
Dim FoundCell As Range
Set FoundCell = Cells.Find("N/A")
Do While Not (FoundCell Is Nothing)
Set FoundCell = Cells.Find("N/A") 'Why

needed?
FoundCell.EntireRow.Delete
Loop
End Sub
------------

-----Original Message-----
Alan,

Try something like

Dim FoundCell As Range
Set FoundCell = Cells.Find(....)
If Not FoundCell Is Nothing Then
FoundCell.EntireRow.Delete
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Alan" wrote in
message
...
After finding a cell using "Find", how do I delete

the
entire row?

Regards,
Alan


.


--

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
Cell Value Found instead of a 1 Rob Excel Discussion (Misc queries) 4 January 12th 09 06:15 PM
Deleting cell data without deleting formula Tom Hall Excel Discussion (Misc queries) 4 October 29th 06 04:07 PM
Change the appearance cell where Find criteria is found in a cell Tomszar Excel Discussion (Misc queries) 3 December 30th 05 02:48 PM
how prevent formula in cell from deleting when deleting value???? sh-boom New Users to Excel 1 September 30th 05 06:12 PM
Need the cell next to one found through If Then workin4alivin New Users to Excel 2 August 10th 05 07:20 PM


All times are GMT +1. The time now is 09:19 AM.

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"