#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 101
Default Dim and set

You're setting a variable, which you do not need to Activate it. You can,
however, Activate it afterwards if you'd like, and that is only if it found
what you were looking for. A simple test would look like this...

If rngFound Is Nothing Then
Msgbox "Nothing was found!"
Else
rngFound.Activate
MsgBox "Cell found at " & rngFound.Address
End If

--
Regards,
Zack Barresse, aka firefytr
To email, remove NOSPAM


"David" wrote in message
...
I tried to do a subsitution on your find statement, but this is failing,
even
though the string exists. I am trying to put the string into a variable,
but
i thought i might and should be able to do it with the constant.

Set rngFound = Cells.Find(What:="9C4754", After:=ActiveCell,
LookIn:=xlFormulas, _ LookAt :=xlWhole, SearchOrder:=xlByRows,
SearchDirection:=xlNext, _ MatchCase:= _ False,
SearchFormat:=False).Activate
--

Thanks for your help Jim,
David


"Jim Thomlinson" wrote:

Set is only required when you are referencing objects like range objects
or
whape objects. In your case SerialNumber is a regualr variable (string,
or
integer or double), so set is not required. However if your find does not
find what it is looking for the code will crash. This is where you would
want
to set a range object

Dim SerialNumber As String
Dim rngFound as Range

SerialNumber = ActiveCell.Offset(1, 3).Value & ActiveCell.Offset(1,
4).Value

set rngFound = Selection.Find(What:=SerialNumber, After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)

if rngfound is nothing then
msgbox "Sorry, not found"
else
rngfound.select
enid if

--
HTH...

Jim Thomlinson


"David" wrote:

Hi Group,

I am having trouble with the follwing. When I try and find, it says it
is
not set.
Dim SerialNumber As String
Set SerialNumber = ActiveCell.Offset(1, 3).Value & ActiveCell.Offset(1,
4).Value
Selection.Find(What:=SerialNumber, After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,
_
MatchCase:=False, SearchFormat:=False).Activate

I tried the last statement with the Variable SerialNumber in ( ), but
it
still says it is not set.

Thanks
--
David



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



All times are GMT +1. The time now is 05:00 PM.

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"