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: 48
Default Worksheets("Sheetname").Select refuses to kick in from User Defined function

Hi all,

I have created a small Function that does the following:
1) Go to a worksheet in my workbook where it should get data
2) Get data of Cell A1
The function (in a simplified version) looks like this:

Function fncGetData(LSheetname As String) As Variant
Worksheets(LSheetname).Select
fncGetData = Cells(1, 1).Value
End Function

I run the function e.g. as Msgbox fncGetData(Sheet2)
(And Sheet 2 exists!!!)

Now when I run the function from VBA it works fine. The sheet is opened and I
get the contents of cell A1 of the Sheet2. Even when I had Sheet1 open.

However, if I run the function from another sheet as a user defined function
it fails to activate the desired sheet and it displays the contents of Cell
A1 of the sheet on which I use the worksheet function.

How can I get this right. I tried DoEvents but that does not work.

Thanks!

--
Message posted via http://www.officekb.com

 
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
Excel Message "user defined type not defined" LEELK01 Excel Discussion (Misc queries) 2 August 14th 09 07:31 AM
How do you save and share "user-defined chart type's" in Excel? Jocelynne Charts and Charting in Excel 1 August 24th 06 08:46 AM
How do you save and share "user-defined chart type's" in Excel? Jocelynne Charts and Charting in Excel 0 August 23rd 06 08:51 PM
"User-defined type not defined" error when trying to send e-mail SupperDuck Excel Programming 9 August 2nd 06 07:36 AM
Excel "Insert Formula" dialog always call my user defined function [email protected][_2_] Excel Programming 0 March 1st 06 02:35 AM


All times are GMT +1. The time now is 04:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"