Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Cells.find restricted to a single range??

I have the below code to search for a number in my sheet.

However, I only want to search the range "rngtest", and if the numbe
does not exist in that range, it should return only a msgbox saying n
such entry.

What should be changed???


Dim iSpecific As integer
Cells.Find(What:=iSpecific, After:=Range("A1"), LookIn:=xlFormulas
LookAt _
:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext
MatchCase _
:=False, SearchFormat:=False).Activate

Cheers

Stef

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default Cells.find restricted to a single range??

Steff,
replace "Cells.Find" with the following, if "rngtest" is a
variable in your code:

rngtest.find

If "rngtest" is a named range in the workbook:

Range("rngtest").find

Cheers, Pete.

-----Original Message-----
I have the below code to search for a number in my sheet.

However, I only want to search the range "rngtest", and

if the number
does not exist in that range, it should return only a

msgbox saying no
such entry.

What should be changed???


Dim iSpecific As integer
Cells.Find(What:=iSpecific, After:=Range("A1"),

LookIn:=xlFormulas,
LookAt _
:=xlWhole, SearchOrder:=xlByColumns,

SearchDirection:=xlNext,
MatchCase _
:=False, SearchFormat:=False).Activate

Cheers

Steff


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Cells.find restricted to a single range??

What if there's no such entry in the range?

I get runtime error if I search for a number that isn't in the range..

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Cells.find restricted to a single range??

Steff,

Try writing your code like

Dim FoundCell As Range
Set FoundCell = RngTest.Find(...)
If FoundCell Is Nothing Then
' no value found in RngTest
Else
FoundCell.Activate
End If

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



"Steff_DK " wrote in
message ...
What if there's no such entry in the range?

I get runtime error if I search for a number that isn't in the

range...


---
Message posted from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Cells.find restricted to a single range??

I get error 424 object req'd...

Dunno why :-/


Dim FoundCell As Range
Set FoundCell = Range("case").Find(What:=iSpecific, After:=Range("A1")
LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext
MatchCase _
:=False, SearchFormat:=False).Activate

If FoundCell Is Nothing Then
MsgBox ("Number doesn't exist.")
Else
FoundCell.Activat

--
Message posted from http://www.ExcelForum.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Cells.find restricted to a single range??

Remove the .Activate at the end of your .Find() method...

--
Regards,

Juan Pablo González

"Steff_DK " wrote in message
...
I get error 424 object req'd...

Dunno why :-/


Dim FoundCell As Range
Set FoundCell = Range("case").Find(What:=iSpecific, After:=Range("A1"),
LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase _
:=False, SearchFormat:=False).Activate

If FoundCell Is Nothing Then
MsgBox ("Number doesn't exist.")
Else
FoundCell.Activate


---
Message posted from http://www.ExcelForum.com/



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
Restricted Cells ab3d4u[_26_] Excel Worksheet Functions 1 February 20th 08 03:44 PM
Restricted Range in Auto filter Subhashis Bhowmick Excel Discussion (Misc queries) 2 June 19th 07 03:38 PM
Password restricted single macro and button michaelberrier Excel Discussion (Misc queries) 1 June 19th 06 10:38 PM
Copy column range of "single word" cells with spaces to a single c nastech Excel Discussion (Misc queries) 3 February 15th 06 05:04 PM
Protecting single cells or a range Ant Excel Discussion (Misc queries) 3 June 23rd 05 03:09 PM


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