Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to ensure function does not refer to cells outside of workbook?

I have written a function that searches for the lowest value in on
workbook... but this workbook is opened together with other workbook
for analysis.

Part of my function is as follows:
If LowestRate Cells(rngStart.Row, lngCol).value Then
LowestRate = Cells(rngStart.Row, lngCol).value

And I perform within my workbook, =search_lowest(O11,2) where the dat
to be search is from O11 to the last column.

Everytime I opened a new workbook, it seems that the reference goes t
a new workbook's O11 to last column. How do I ensure that does no
happen? Do I specify the full path of the workbook, worksheet in m
module? If so, what is the syntax for that? Thanks.

r

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default How to ensure function does not refer to cells outside of workbook?

Your Cells statements don't specify the sheet nor the workbook. When not
specified, VBA assumes the active sheet.

Fully clarify the Cells statement using a workbook or worksheet variable -
something like...

Dim wks as Worksheet

Set wks = ThisWorkbook.Worksheets("XYZ")

If LowestRate wks.Cells(rngStart.Row, lngCol).Value

OR

Dim wkb as Workbook

Set wkb = ThisWorkbook

If LowestRate wkb.Worksheets("XYZ").Cells(rngStart.Row, lngCol).Value

OR you can access the correct sheet by traveling up the object tree of your
rngStart variable

'rngStart.Parent = the worksheet the defined range is located in
If LowestRate rngStart.Parent.Cells(rngStart.Row, lngCol).Value

--
__________________
Robert Rosenberg
R-COR Consulting Services
Microsoft MVP - Excel


"richardbok " wrote in message
...
I have written a function that searches for the lowest value in one
workbook... but this workbook is opened together with other workbooks
for analysis.

Part of my function is as follows:
If LowestRate Cells(rngStart.Row, lngCol).value Then
LowestRate = Cells(rngStart.Row, lngCol).value

And I perform within my workbook, =search_lowest(O11,2) where the data
to be search is from O11 to the last column.

Everytime I opened a new workbook, it seems that the reference goes to
a new workbook's O11 to last column. How do I ensure that does not
happen? Do I specify the full path of the workbook, worksheet in my
module? If so, what is the syntax for that? Thanks.

rb


---
Message posted from http://www.ExcelForum.com/



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
How to ensure workbook is saved before exiting Excel? Kathy Love Excel Discussion (Misc queries) 6 December 9th 09 09:18 PM
Ensure that required cells have beeb updated on saving the workboo Margaret Excel Discussion (Misc queries) 1 January 13th 09 02:54 PM
When opening a workbook, need to ensure user opens in a certain ce Gover Excel Discussion (Misc queries) 4 April 11th 07 03:06 PM
how do I ensure that the sum of two cells does not exceed a set fi lennysc14 Excel Worksheet Functions 3 July 5th 05 11:51 PM
ensure backup function occurs once a month Rhonda[_2_] Excel Programming 3 September 16th 03 04:09 PM


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