Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
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  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default why is range empty?

The only thing I c an see is a missing bracket

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

I would also clear rngToFind as precaaution each iteration of the loop

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


--
HTH

Bob Phillips

"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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default why is range empty?

Not too sure. It worked fine when I tried it. It did not compile however
until I changed

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

to

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

Which I assume you have done. The only thing I can think of is the values
that you are looking for may be padded with blanks. Try changing to

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

HTH


"JT" wrote:

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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 252
Default why is range empty?

Bob,

If you
Set rngToFind = Nothing,

how can you then
Set rngToFind = rngToFind.Offset(-1, 0)



"Bob Phillips" wrote:

The only thing I c an see is a missing bracket

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

I would also clear rngToFind as precaaution each iteration of the loop

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


--
HTH

Bob Phillips

"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
Test if the range is empty dan Excel Discussion (Misc queries) 6 December 21st 06 03:59 PM
Check for empty range in vba Phil Excel Discussion (Misc queries) 1 April 28th 06 09:57 PM
why is range empty? JT Excel Discussion (Misc queries) 1 March 9th 05 12:26 PM
sum next two non-empty cells in a range Spencer Hutton Excel Worksheet Functions 1 January 9th 05 11:29 PM
determinate if a range is empty GUS Excel Programming 2 October 30th 03 01:00 AM


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