Getting different values for a function each time

martha555

New Member
Joined
Jun 28, 2005
Messages
41
:biggrin: hi,
I have written the following code in a module which is:

Function CntShts()
Application.Volatile
CntShts = ThisWorkbook.Sheets.Count - 1
End Function

In the cell a2 I have written =CntShts()

However, I get a different value in cell a2, everytime, i.e., "#ref", "#value" or the answer( a number). When I rewrite the function in another cell, then the actual value is displayed in cell a2. Why is this so? Please help.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

martha555

New Member
Joined
Jun 28, 2005
Messages
41
hi thanx for the response. Try closing and opening the file a few times, becoz it is happening here. How do I rectify it.
 
Upvote 0

Forum statistics

Threads
1,195,595
Messages
6,010,632
Members
441,558
Latest member
lambierules

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top