#1   Report Post  
JT
 
Posts: n/a
Default why is range empty?

In the code below, rngToFind is being filled correctly.
The problem is that rngFound is always empty. On sheet
("A"), there is data in column 1. Some items will match
and some won't. If the item (from sheet "P") is not found
in the rngFound (from sheet "A") then the item on
sheeet "P" should be deleted.

This is not happening. When I put my coursor over
rngFound it says empty.

Any suggestions or help would be appreciated. Thanks....

Dim rngToFind As Range
Dim rngFound As Range

Set rngToFind = Sheets("P").Range("A" & lstrowPP).End(xlUp)

Do While rngToFind.Row 1

Set rngFound = Sheets("A").Columns(1).Find rngToFind.Value)

Set rngToFind = rngToFind.Offset(-1, 0)

If Not rngFound Is Nothing Then
rngToFind.Offset(1, 0).EntireRow.Delete

End If
Loop

  #2   Report Post  
Jim Rech
 
Posts: n/a
Default

This works for me. Adjust the Find arguments to do the specific type of
Find you want. See VBA help for more on Find.

Sub FindOrDelete()
Dim Cell As Range
Dim PRg As Range
Dim DeleteRg As Range
With Worksheets("P")
Set PRg = .Range("A2", .Range("A2").End(xlDown))
End With
For Each Cell In PRg
If Worksheets("A").Columns(1) _
.Find(Cell.Value, , xlValues, xlWhole) Is Nothing Then
If DeleteRg Is Nothing Then
Set DeleteRg = Cell
Else
Set DeleteRg = Union(DeleteRg, Cell)
End If
End If
Next
If Not DeleteRg Is Nothing Then
DeleteRg.EntireRow.Delete
End If
End Sub


--
Jim Rech
Excel MVP
"JT" wrote in message
...
| In the code below, rngToFind is being filled correctly.
| The problem is that rngFound is always empty. On sheet
| ("A"), there is data in column 1. Some items will match
| and some won't. If the item (from sheet "P") is not found
| in the rngFound (from sheet "A") then the item on
| sheeet "P" should be deleted.
|
| This is not happening. When I put my coursor over
| rngFound it says empty.
|
| Any suggestions or help would be appreciated. Thanks....
|
| Dim rngToFind As Range
| Dim rngFound As Range
|
| Set rngToFind = Sheets("P").Range("A" & lstrowPP).End(xlUp)
|
| Do While rngToFind.Row 1
|
| Set rngFound = Sheets("A").Columns(1).Find rngToFind.Value)
|
| Set rngToFind = rngToFind.Offset(-1, 0)
|
| If Not rngFound Is Nothing Then
| rngToFind.Offset(1, 0).EntireRow.Delete
|
| End If
| Loop
|


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
create range bar graph Aussie1497 Charts and Charting in Excel 2 April 26th 23 11:47 AM
Dynamic Print Range Help waxwing Excel Worksheet Functions 2 February 21st 05 03:47 PM
Define a range based on another named range Basil Excel Worksheet Functions 2 February 21st 05 01:47 PM
empty variable range S1 Excel Discussion (Misc queries) 5 January 28th 05 02:33 PM
named range refers to: in a chart Spencer Hutton Excel Discussion (Misc queries) 1 December 14th 04 10:15 PM


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