Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Find and Delete Row from Range

I have a named range, that I would like to search for a name, and then delete
the record (row) in that range that contains the name I found.

I can do a Range.Find to find the name, but it returns me a Address of the
cell on the spreadsheet. I was wondering how would I find the location of the
cell relative to the Range, rather than relative to the worksheet.

If I used the Macro Recorder to right click on the cell containing the name,
and choose "Delete Table Row", I get the following code:
Selection.ListObject.ListRows(61).Delete

The problem with that is that the 61, is the row number relative to the
named range, and I don't know how to get that programatically.

Any help would be appreciated.

Thanks,
Steve

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Find and Delete Row from Range

If your range is named "Steve" and the text you are looking for is "Haack"
then:

Sub demo()
For Each r In Range("Steve")
If r.Value = "Haack" Then
r.EntireRow.Delete
Exit Sub
End If
Next
End Sub


will remove the row with that text in it.
--
Gary's Student
gsnu200702


"Steve Haack" wrote:

I have a named range, that I would like to search for a name, and then delete
the record (row) in that range that contains the name I found.

I can do a Range.Find to find the name, but it returns me a Address of the
cell on the spreadsheet. I was wondering how would I find the location of the
cell relative to the Range, rather than relative to the worksheet.

If I used the Macro Recorder to right click on the cell containing the name,
and choose "Delete Table Row", I get the following code:
Selection.ListObject.ListRows(61).Delete

The problem with that is that the 61, is the row number relative to the
named range, and I don't know how to get that programatically.

Any help would be appreciated.

Thanks,
Steve

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Find and Delete Row from Range

Duh, that was pretty simple....

Thanks a bunch.

"Steve Haack" wrote:

I have a named range, that I would like to search for a name, and then delete
the record (row) in that range that contains the name I found.

I can do a Range.Find to find the name, but it returns me a Address of the
cell on the spreadsheet. I was wondering how would I find the location of the
cell relative to the Range, rather than relative to the worksheet.

If I used the Macro Recorder to right click on the cell containing the name,
and choose "Delete Table Row", I get the following code:
Selection.ListObject.ListRows(61).Delete

The problem with that is that the 61, is the row number relative to the
named range, and I don't know how to get that programatically.

Any help would be appreciated.

Thanks,
Steve

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Find and Delete Row from Range

OK, then another (probably) dumb question....
When I am looking at R.Value, I can find the name that I am searching for.
But let's say, that once I find the one I am looking for, I want to then look
at other cells on the same row, within the range "Steve" before deleteing
that row? How would I reference the other cells on the same row in that range?

"Gary''s Student" wrote:

If your range is named "Steve" and the text you are looking for is "Haack"
then:

Sub demo()
For Each r In Range("Steve")
If r.Value = "Haack" Then
r.EntireRow.Delete
Exit Sub
End If
Next
End Sub


will remove the row with that text in it.
--
Gary's Student
gsnu200702


"Steve Haack" wrote:

I have a named range, that I would like to search for a name, and then delete
the record (row) in that range that contains the name I found.

I can do a Range.Find to find the name, but it returns me a Address of the
cell on the spreadsheet. I was wondering how would I find the location of the
cell relative to the Range, rather than relative to the worksheet.

If I used the Macro Recorder to right click on the cell containing the name,
and choose "Delete Table Row", I get the following code:
Selection.ListObject.ListRows(61).Delete

The problem with that is that the 61, is the row number relative to the
named range, and I don't know how to get that programatically.

Any help would be appreciated.

Thanks,
Steve

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Find and Delete Row from Range

Sub demo2()
For Each r In Range("Steve")
If r.Value = "Haack" Then
i = r.Row
MsgBox ("the row is " & i)
MsgBox (Cells(i, 1).Value & " is in the first cell in the row")
MsgBox (Cells(i, 2).Value & " is in the second cell in the row")
Exit Sub
End If
Next



--
Gary's Student
gsnu200702


"Steve Haack" wrote:

OK, then another (probably) dumb question....
When I am looking at R.Value, I can find the name that I am searching for.
But let's say, that once I find the one I am looking for, I want to then look
at other cells on the same row, within the range "Steve" before deleteing
that row? How would I reference the other cells on the same row in that range?

"Gary''s Student" wrote:

If your range is named "Steve" and the text you are looking for is "Haack"
then:

Sub demo()
For Each r In Range("Steve")
If r.Value = "Haack" Then
r.EntireRow.Delete
Exit Sub
End If
Next
End Sub


will remove the row with that text in it.
--
Gary's Student
gsnu200702


"Steve Haack" wrote:

I have a named range, that I would like to search for a name, and then delete
the record (row) in that range that contains the name I found.

I can do a Range.Find to find the name, but it returns me a Address of the
cell on the spreadsheet. I was wondering how would I find the location of the
cell relative to the Range, rather than relative to the worksheet.

If I used the Macro Recorder to right click on the cell containing the name,
and choose "Delete Table Row", I get the following code:
Selection.ListObject.ListRows(61).Delete

The problem with that is that the 61, is the row number relative to the
named range, and I don't know how to get that programatically.

Any help would be appreciated.

Thanks,
Steve

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 to Delete blanks between a range and populate only the names inthe given range Yuvraj Excel Discussion (Misc queries) 2 November 4th 09 08:32 PM
How to Delete a Range in Closed Workbook (to Replace Delete Query) [email protected] Excel Discussion (Misc queries) 1 March 8th 06 10:10 AM
Range.Delete and Range.Resize.Name performance issues Test.File Excel Programming 0 February 15th 05 03:33 PM
find and delete duplicate entries in two columns or find and prin. campare 2 columns of numbers-find unique Excel Programming 1 November 24th 04 04:09 PM
find and delete text, find a 10-digit number and put it in a textbox Paul Excel Programming 3 November 16th 04 04:21 PM


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