Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Sue Sue is offline
external usenet poster
 
Posts: 285
Default Finding outside set range

I am using Excel 2000 and have the following code:
With Worksheets("Data Lists").Range(WorkRange)
Set MyEdit = Cells.Find(AccCode, , xlValues, xlWhole, xlByColumns)
End With
This does find the AccCode in the WorkRange BUT it also finds the AccCode
outside the WorkRange. Why? How can I stop that?
Sue
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 257
Default Finding outside set range

You're probably thinking that the With header limits everything that happens
inside it to the Range you specified. But that isn't how it works.

The With statement makes available a sort of default parent object inside
that section - but only AVAILABLE. So your With Worksheets("Data
Lists").Range(WorkRange) allows you, inside that section, to refer to
".Cells.Count" (notice the leading dot), and it'll tell you how many cells
are in Worksheets("Data Lists").Range(WorkRange).Cells.Count, or to
".Font.Bold" and it'll give you True or False depending on whether
Worksheets("Data Lists").Range(WorkRange).Font.Bold is True or False. The
leading dot specifies that the parent object for that term is to be whatever
you specified in the With statement.

But you never used a leading dot in any term in that section; you said "Set
MyEdit = Cells.Find(AccCode, , xlValues, xlWhole, xlByColumns)". Therefore
it did the Find inside the range defined by Cells with no leading dot; Access
assumes the default parent object for Cells is ActiveSheet, I believe, so it
looked in the whole active worksheet. What you want, I take it, is "Set
MyEdit = .Find(AccCode, , xlValues, xlWhole, xlByColumns)", where ".Find"
means "Worksheets("Data Lists").Range(WorkRange).Find". You see?

--- "Sue" wrote:
I am using Excel 2000 and have the following code:
With Worksheets("Data Lists").Range(WorkRange)
Set MyEdit = Cells.Find(AccCode, , xlValues, xlWhole, xlByColumns)
End With
This does find the AccCode in the WorkRange BUT it also finds the AccCode
outside the WorkRange. Why? How can I stop that?

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
Finding the corresponding value in a range? Zuo Excel Worksheet Functions 4 February 25th 10 12:45 PM
finding a value between a range Susan Excel Worksheet Functions 9 March 6th 07 12:07 AM
Finding the End of a Range BigH Excel Programming 9 February 20th 06 10:02 PM
Finding a value associated with a range Raymond Gallegos Excel Worksheet Functions 5 November 25th 05 08:38 PM
finding name within range sheila Excel Worksheet Functions 4 September 14th 05 07:52 AM


All times are GMT +1. The time now is 10:14 AM.

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

About Us

"It's about Microsoft Excel"