LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Last row in a particular sheet / workbook

I have a UDF to return the last row in a particular sheet:

Function Get_LastRow(Sheet As String) As Long
Application.Volatile True

Get_LastRow = Sheets(Sheet).UsedRange.Rows.Count

End Function

Now here is the problem:
* This UDF is stored in a module in workbook WB1.
* WB1 Sheet1 has 10 rows. WB1 Sheet2 has 9 rows. I call the UDF from WB1
Sheet3 twice to return the last rows of WB1 Sheet1 (10) and WB1 Sheet2 (9).
* At the same time I have workbook WB2 open. WB2 Sheet1 has 6 rows, WB2
Sheet2 has 3 rows. WB2 uses some results from WB1. WB2 has the focus - it is
displayed on top.
* When I do a Full Recalculate (F9) with WB2 on top, then switch to WB1 I
find that the UDF has put 6 and 3 in WB1. I have tried renaming Sheet1 and
Sheet2 in WB2 to something else, then the recalculate results in #VALUE in
WB1.
(When I recalculate with WB1 on top I receive the expected results 10 and 9.)

How can I get the last row of the sheet from the workbook that calls the UDF?

Thanks for your help!
 
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
Merge 7 files to 1 workbook/7Sheets and then 1 sheet of the new workbook Otto Moehrbach[_2_] Excel Programming 2 August 7th 08 01:33 AM
Help needed: Getting all sheet setup data from one workbook toanother workbook Lostguy Excel Programming 1 July 8th 08 02:43 PM
Copy rows from multiple workbook into a different workbook (sheet) Yossy Excel Programming 19 May 11th 08 12:34 AM
Select sheet tabs in workbook & save to separate workbook files stratocaster Excel Worksheet Functions 2 March 1st 06 03:35 PM


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