Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|