Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 216
Default Function and needing to Refresh

Hi. I've written the following simple function that
appears to work well. However, at various times I will
receive the #VALUE error and will need to hit F9
(recalculate) to get the correct answers. This happens
repeatedly if I open another workbook, change something,
and come back.

My code is:

Option Explicit

Function InviteBack(myType, myMonth)
Application.Volatile True
Dim myRange As range
Dim j As Integer
Set myMonth = Worksheets(myMonth)
Dim myCell As range
j = 0
Set myRange = myMonth.range("n4:n39")
For Each myRange In myRange.Cells
If myRange.Formula = myType Then
If UCase((myRange.Cells.Offset(0, 4).Formula))
= "Y" Then
j = j + 1
End If
End If
Next
InviteBack = j
End Function

Thanks,
Mike.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Function and needing to Refresh

Without testing it, I suspect that the problem is the qualification
of your objects.

Worksheets(myMonth)

is, by default, evaluated for the ActiveWorkbook. If a calculation
occurs with another workbook active, the subscript out of range
error will generate a #VALUE! error.

If the function is in the same workbook as the calling cell,
qualifying Worksheets(myMonth) with ThisWorkbook:

ThisWorkbook.Worksheets(myMonth)

should prevent that error. If it's not in the same workbook, try

Application.Caller.Parent.Parent.Worksheets(myMont h)



In article ,
"Mike" wrote:

Hi. I've written the following simple function that
appears to work well. However, at various times I will
receive the #VALUE error and will need to hit F9
(recalculate) to get the correct answers. This happens
repeatedly if I open another workbook, change something,
and come back.

My code is:

Option Explicit

Function InviteBack(myType, myMonth)
Application.Volatile True
Dim myRange As range
Dim j As Integer
Set myMonth = Worksheets(myMonth)
Dim myCell As range
j = 0
Set myRange = myMonth.range("n4:n39")
For Each myRange In myRange.Cells
If myRange.Formula = myType Then
If UCase((myRange.Cells.Offset(0, 4).Formula))
= "Y" Then
j = j + 1
End If
End If
Next
InviteBack = j
End Function

Thanks,
Mike.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 216
Default Function and needing to Refresh

Thanks!

ThisWorkbook.Worksheets(myMonth) solved the problem.

Mike.


-----Original Message-----
Without testing it, I suspect that the problem is the

qualification
of your objects.

Worksheets(myMonth)

is, by default, evaluated for the ActiveWorkbook. If a

calculation
occurs with another workbook active, the subscript out

of range
error will generate a #VALUE! error.

If the function is in the same workbook as the calling

cell,
qualifying Worksheets(myMonth) with ThisWorkbook:

ThisWorkbook.Worksheets(myMonth)

should prevent that error. If it's not in the same

workbook, try

Application.Caller.Parent.Parent.Worksheets(myMont h)



In article ,
"Mike" wrote:

Hi. I've written the following simple function that
appears to work well. However, at various times I

will
receive the #VALUE error and will need to hit F9
(recalculate) to get the correct answers. This

happens
repeatedly if I open another workbook, change

something,
and come back.

My code is:

Option Explicit

Function InviteBack(myType, myMonth)
Application.Volatile True
Dim myRange As range
Dim j As Integer
Set myMonth = Worksheets(myMonth)
Dim myCell As range
j = 0
Set myRange = myMonth.range("n4:n39")
For Each myRange In myRange.Cells
If myRange.Formula = myType Then
If UCase((myRange.Cells.Offset(0, 4).Formula))
= "Y" Then
j = j + 1
End If
End If
Next
InviteBack = j
End Function

Thanks,
Mike.

.

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
Table function, 2 variables. Problem with update/refresh lorenzo Excel Worksheet Functions 5 November 25th 06 10:55 PM
Refresh/Recalculate a Custom Function dch3 Excel Worksheet Functions 1 July 31st 06 01:59 PM
Customized function (in cell) does not refresh value :o( MarcL Excel Discussion (Misc queries) 3 February 28th 06 08:57 PM
student needing help w/vlookup function grading criteria Julie Excel Worksheet Functions 2 October 21st 05 01:13 PM
function values do not refresh Jacob Excel Worksheet Functions 2 April 1st 05 09:51 PM


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