Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 109
Default external range in VBA (user defined formula)

It looks like you are not referencing the range fully. Perhaps it
should be something like :-

Workbooks("MyWorkBook.xls").Worksheets("Sheet1").R ange("Forecast").Cells(1,
1).Value

It is a bad programming habit to leave out the Workbook and Worksheet
identifiers. Ok, if everything is in one Workbook you can omit this
bit safely. Although you may get away with it most of the time, it can
lead to problems as your macros get more complicated. You become more
advanced and don't have to use .Select very often. I notice that you
are, at least, putting the .Value <grin. Omitting this can sometimes
produce unpredictable results - very difficult to find & debug.


Regards
BrianB
================================================== ==



(Gord) wrote in message . com...
Hello. I was wondering if it is possible to reference an external
range
in VBA. I tried to do it two different ways, as shown in the code
below
but neither of them worked. I put the error messages I got in the
comments
above the particular line in which that error occurred.

Background: What I'm ultimately trying to do is make a user defined
formula
to replace an ugly formula(that takes two or three times longer to
calculate than it needs to)
that has a whole bunch of IsError() and VLookup() If(), and match()
functions,
many of which take external ranges as parameters.


Thanks for any insight,

Gord.



On Error GoTo zero

'// Forecast is an External Range. TableNames is a local Range

'// Works
MsgBox " contents of cell in local range: " &
Range("TableNames").Cells(1, 1).Value

'// doesn't work: Method 'Range' of Object '_Global' failed
MsgBox " contents of cell in external range: " &
Range("Forecast").Cells(1, 1).Value

'// doesn't work: application defined or object defined
error
MsgBox " contents of cell in external range: " &
Names("Forecast").RefersToRange.Cells(1, 1).Value

GoTo the_end

zero:
MsgBox "error: " & Err.Description

the_end:

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
help text for user defined formula WJvR Excel Worksheet Functions 2 July 23rd 08 04:34 PM
User-defined range for graph royend Excel Discussion (Misc queries) 3 September 4th 07 09:11 AM
Passing a range to a user defined function Gary Nelson Excel Discussion (Misc queries) 1 July 19th 07 04:22 PM
"User-defined type not defined" message in Excel RW1946 Excel Discussion (Misc queries) 0 August 31st 05 12:14 PM
external range in VBA (user defined formula) Tim Zych[_2_] Excel Programming 0 July 22nd 03 02:02 AM


All times are GMT +1. The time now is 11:41 PM.

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"