Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Tim Tim is offline
external usenet poster
 
Posts: 145
Default "object variable or with bock variable not set" - quick reply greatly appreciated!

Hi,

My VBA is having problems (resulting in the above error message) at the
following line: -

Range(Range("RefNum").Find(Ref, LookAt:=xlWhole).Address).Select

- 'RefNum' is a dynamic range (and refers to the correct range when chosen
via 'Edit', 'Goto')
- 'Ref' is a variable which it recognises as '1' when the mouse hovers over
the error-highlighted code

Its purpose is to locate the correct row on another sheet (which contains
the 'RefNum' range) from a unique reference number ('Ref') on this sheet
(then copy relevant pieces of data from one to the other).

This forms part of a much bigger piece of vba, and was previously working
properly; i guess i've changed something, but i can't see what. Can anyone
tell me what i'm doing wrong? Do i need to post the rest of the code?

Thanks,

Tim


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default "object variable or with bock variable not set" - quick replygreatly appreciated!

If Ref isn't found, then the .address will fail.

..find inherits all the settings that the last Find (either in code or by the
user) applied.

I'd do:

Dim FoundCell as range
...
with activesheet.range("RefNum")
Set foundcell = .Cells.Find(what:=ref, _
after:=.cells(.cells.count), _
LookIn:=xlValues, _
lookat:=xlWhole, _
searchorder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False)
end with

if foundcell is nothing then
msgbox Ref & " wasn't found"
else
'must be on the activesheet
foundcell.select
end if


Tim wrote:

Hi,

My VBA is having problems (resulting in the above error message) at the
following line: -

Range(Range("RefNum").Find(Ref, LookAt:=xlWhole).Address).Select

- 'RefNum' is a dynamic range (and refers to the correct range when chosen
via 'Edit', 'Goto')
- 'Ref' is a variable which it recognises as '1' when the mouse hovers over
the error-highlighted code

Its purpose is to locate the correct row on another sheet (which contains
the 'RefNum' range) from a unique reference number ('Ref') on this sheet
(then copy relevant pieces of data from one to the other).

This forms part of a much bigger piece of vba, and was previously working
properly; i guess i've changed something, but i can't see what. Can anyone
tell me what i'm doing wrong? Do i need to post the rest of the code?

Thanks,

Tim


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
Tim Tim is offline
external usenet poster
 
Posts: 145
Default "object variable or with bock variable not set" - quick reply greatly appreciated!

Thanks Dave. Worked a treat ;o)

"Dave Peterson" wrote in message
...
If Ref isn't found, then the .address will fail.

.find inherits all the settings that the last Find (either in code or by
the
user) applied.

I'd do:

Dim FoundCell as range
...
with activesheet.range("RefNum")
Set foundcell = .Cells.Find(what:=ref, _
after:=.cells(.cells.count), _
LookIn:=xlValues, _
lookat:=xlWhole, _
searchorder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False)
end with

if foundcell is nothing then
msgbox Ref & " wasn't found"
else
'must be on the activesheet
foundcell.select
end if


Tim wrote:

Hi,

My VBA is having problems (resulting in the above error message) at the
following line: -

Range(Range("RefNum").Find(Ref, LookAt:=xlWhole).Address).Select

- 'RefNum' is a dynamic range (and refers to the correct range when
chosen
via 'Edit', 'Goto')
- 'Ref' is a variable which it recognises as '1' when the mouse hovers
over
the error-highlighted code

Its purpose is to locate the correct row on another sheet (which contains
the 'RefNum' range) from a unique reference number ('Ref') on this sheet
(then copy relevant pieces of data from one to the other).

This forms part of a much bigger piece of vba, and was previously working
properly; i guess i've changed something, but i can't see what. Can
anyone
tell me what i'm doing wrong? Do i need to post the rest of the code?

Thanks,

Tim


--

Dave Peterson



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
Unexplained/Unknow"Object variable or With block variable not set" Wellie Excel Programming 1 August 12th 06 09:04 AM
Getting "Object Variable or With Block Variable not set" error Suraj[_2_] Excel Programming 9 February 25th 06 09:11 AM
Why "object variable or with block variable not set" error? SSjmg2477 Excel Programming 2 February 14th 06 11:02 PM
"Object Variable or With Block Variable Not Set" error help request Ken Loomis Excel Programming 8 June 27th 05 10:13 PM
Ogilvy Help :) - "Object variable or With block variable not set" Mike Taylor Excel Programming 1 December 16th 03 07:21 AM


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