Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default set and then select

Hi group,

I am doing a find for text. I thought i had to Set as a range, then do the
"Find" then select it, but I am getting an error.
This is the code I have that produces the Error:
Dim FoundCell As Range
Set FoundCell = Selection.Find(What:="ORDER:", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

Any help would be appreciated.
--
David
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default But

Hi again,
I got part of this, but it is part of a loop. I was able to select the cell
in the first instance of the find, but when the loop goes around again, it
fails. The loop includes the Set and Find again, but the FoundCell has
nothing in it at this point, so it can not be activated.

New Code:
Dim FoundCell As Range
Set FoundCell = Selection.Find(What:="ORDER:", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
Range(FoundCell.Address).Activate <-This is now where it fails.
--
David


"David" wrote:

Hi group,

I am doing a find for text. I thought i had to Set as a range, then do the
"Find" then select it, but I am getting an error.
This is the code I have that produces the Error:
Dim FoundCell As Range
Set FoundCell = Selection.Find(What:="ORDER:", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

Any help would be appreciated.
--
David

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default But

Hi David,

You can test FoundCell with something like this:

If Not FoundCell Is Nothing Then
'a match was found.
FoundCell.Activate
End If



--
Hope that helps.

Vergel Adriano


"David" wrote:

Hi again,
I got part of this, but it is part of a loop. I was able to select the cell
in the first instance of the find, but when the loop goes around again, it
fails. The loop includes the Set and Find again, but the FoundCell has
nothing in it at this point, so it can not be activated.

New Code:
Dim FoundCell As Range
Set FoundCell = Selection.Find(What:="ORDER:", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
Range(FoundCell.Address).Activate <-This is now where it fails.
--
David


"David" wrote:

Hi group,

I am doing a find for text. I thought i had to Set as a range, then do the
"Find" then select it, but I am getting an error.
This is the code I have that produces the Error:
Dim FoundCell As Range
Set FoundCell = Selection.Find(What:="ORDER:", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

Any help would be appreciated.
--
David

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default But

Hi Again,
I am able to Select the cell on the first instance, but in the loop on the
second instance it fails. "Object Variable or With block variable not set"

Thanks,
--
David


"Vergel Adriano" wrote:

Hi David,

You can test FoundCell with something like this:

If Not FoundCell Is Nothing Then
'a match was found.
FoundCell.Activate
End If



--
Hope that helps.

Vergel Adriano


"David" wrote:

Hi again,
I got part of this, but it is part of a loop. I was able to select the cell
in the first instance of the find, but when the loop goes around again, it
fails. The loop includes the Set and Find again, but the FoundCell has
nothing in it at this point, so it can not be activated.

New Code:
Dim FoundCell As Range
Set FoundCell = Selection.Find(What:="ORDER:", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
Range(FoundCell.Address).Activate <-This is now where it fails.
--
David


"David" wrote:

Hi group,

I am doing a find for text. I thought i had to Set as a range, then do the
"Find" then select it, but I am getting an error.
This is the code I have that produces the Error:
Dim FoundCell As Range
Set FoundCell = Selection.Find(What:="ORDER:", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

Any help would be appreciated.
--
David

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default But

Hi David,

I'm not sure what you mean by being able to select on the first instance as
there is no loop in the code that you provided. But basically, the reason
you get the error is if Find does not find any match, it returns Nothing.
Using the code you provided, try it this way:

Dim FoundCell As Range
Set FoundCell = Selection.Find(What:="ORDER:", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
'Range(FoundCell.Address).Activate <-This is now where it fails.
If Not FoundCell is Nothing Then
FoundCell.Activate
End if



--
Hope that helps.

Vergel Adriano


"David" wrote:

Hi Again,
I am able to Select the cell on the first instance, but in the loop on the
second instance it fails. "Object Variable or With block variable not set"

Thanks,
--
David


"Vergel Adriano" wrote:

Hi David,

You can test FoundCell with something like this:

If Not FoundCell Is Nothing Then
'a match was found.
FoundCell.Activate
End If



--
Hope that helps.

Vergel Adriano


"David" wrote:

Hi again,
I got part of this, but it is part of a loop. I was able to select the cell
in the first instance of the find, but when the loop goes around again, it
fails. The loop includes the Set and Find again, but the FoundCell has
nothing in it at this point, so it can not be activated.

New Code:
Dim FoundCell As Range
Set FoundCell = Selection.Find(What:="ORDER:", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
Range(FoundCell.Address).Activate <-This is now where it fails.
--
David


"David" wrote:

Hi group,

I am doing a find for text. I thought i had to Set as a range, then do the
"Find" then select it, but I am getting an error.
This is the code I have that produces the Error:
Dim FoundCell As Range
Set FoundCell = Selection.Find(What:="ORDER:", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

Any help would be appreciated.
--
David



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default But

Maybe you should be using the FindNext method:
myRange = Range("WhateverYouWant")
With Worksheets(1).Range(myRange)
Set c = .Find(2, lookin:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Value = 5
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With


"David" wrote:

Hi again,
I got part of this, but it is part of a loop. I was able to select the cell
in the first instance of the find, but when the loop goes around again, it
fails. The loop includes the Set and Find again, but the FoundCell has
nothing in it at this point, so it can not be activated.

New Code:
Dim FoundCell As Range
Set FoundCell = Selection.Find(What:="ORDER:", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
Range(FoundCell.Address).Activate <-This is now where it fails.
--
David


"David" wrote:

Hi group,

I am doing a find for text. I thought i had to Set as a range, then do the
"Find" then select it, but I am getting an error.
This is the code I have that produces the Error:
Dim FoundCell As Range
Set FoundCell = Selection.Find(What:="ORDER:", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

Any help would be appreciated.
--
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA: Column Select then Data Select then return to cell A1 James C[_2_] Excel Discussion (Misc queries) 3 February 1st 10 11:35 AM
Macro to select cells without a certain value and select a menu it Guy[_2_] Excel Worksheet Functions 9 January 2nd 09 05:21 PM
End Select without Select Case, Block If without End If errors Atreides Excel Programming 12 November 17th 06 05:10 PM
In Excel 2000, How do you select the whole of a worksheet (Select. Rascal Excel Discussion (Misc queries) 1 March 5th 05 12:03 AM
In Excel 2000, How do you select the whole of a worksheet (Select. Rascal Excel Discussion (Misc queries) 1 March 4th 05 11:59 PM


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