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: 4
Default Why I got wrong result from nested function?

Hello!

In VBA I made two functions: Func1 and Func2 (code is below). They
work on that principle:
- Let say that we wrote on Sheet2 arbitrary values in range A1:B27.
- Now let say that I wrote on Sheet1 in Cell C4 "=Func1()". I get
result 4 what is of course wrong. The result should be number of the
last row on Sheet2 - that is 27.
- Correct result I get if I call that "Func1" from Sub1.

Look like I overlook something but I don't know what. Can anybody help
me with that problem so that Func1 will return correct result which is
27?

---------------------
Code from the module:
---------------------
Option Explicit

Function Func1()
Dim strWsName As String

strWsName = "Sheet2"
Func1 = Func2(strWsName)
End Function

Function Func2(strSh As String)
Dim lngLastRow As Long, oWS As Worksheet

Set oWS = ActiveSheet

Sheets(strSh).Select
Range("A2").Select
ActiveCell.End(xlDown).Select
lngLastRow = ActiveCell.Row
Debug.Print "lngLastRow: " & lngLastRow

oWS.Select
Set oWS = Nothing

Func2 = lngLastRow
End Function

Sub Sub1()
Debug.Print "Work Ok: " & Func2("Sheet2")
End Sub


Thank you!
 
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
Wrong Result with an IF function Thij_rahya Excel Worksheet Functions 6 July 23rd 09 09:29 PM
What is wrong with this nested function? A little stuck Excel Worksheet Functions 3 July 15th 09 08:38 AM
wrong result if function values over 256 abracadabra Excel Worksheet Functions 4 December 27th 08 06:10 PM
EXCEL 2000 - IF function returns wrong result from logical test Sean Duffy Excel Worksheet Functions 8 October 15th 08 09:58 PM
excel result return wrong calcuation result garyww Excel Worksheet Functions 0 August 14th 06 05:02 AM


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