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

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
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,214,606
Messages
6,120,492
Members
448,967
Latest member
visheshkotha

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
Back
Top