Auto-update cells defined by UDF

c_m

Well-known Member
Joined
May 29, 2008
Messages
836
Hello,

I have number of user defined functions used in the spreadsheet. For some reasons, the values are not updated automatically sometimes. I checked into tools-options-calculation-automatic. Are there any other settings i should know of so that the values are updated automatically?

thanks in advance
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

egiannaros

New Member
Joined
Mar 14, 2008
Messages
42
I tried using the Volatile Method for a UDF that I have which returns the windows username of the person who opens the file. It doesn't seem to be working for me. :confused:

Function UserNameWindows() As String
Application.Volatile
UserNameWindows = Environ("USERNAME")
End Function

The function only works when I click in the cell P3 and Press Shift+F3. Cell P3 reads as follows:

=UserNameWindows()

Is this Volatile Method not working because the Function has no arguments?

Does someone have another method for automating this function so it always updates? Thanks in advance.
 
Upvote 0

Paddy1979

Well-known Member
Joined
Sep 23, 2005
Messages
608
You could try a different approach.

Code:
Private Sub Workbook_Open()
 Sheet1.Range("A1:A10").Value = Application.UserName
End Sub
 
Upvote 0

egiannaros

New Member
Joined
Mar 14, 2008
Messages
42
You could try a different approach.

Code:
Private Sub Workbook_Open()
 Sheet1.Range("A1:A10").Value = Application.UserName
End Sub

I tried this code in the VBA for "Sheet1" , "ThisWorkbook", and in one of my Modules. I couldn't get it to work in any of those 3 scenarios. (I made the change, closed the file and reopened the file.)

Also, it has to be the windows login username, not the office username (because that is just my company's name). My UDF code gets the windows login but I just can't seem to figure out how to have it automatically update when you open the file or recalc.

Does anyone know of another way to do this where it updates automatically?
 
Upvote 0

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
40,364
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
Application.Volatile will cause your UDF to recalculate when the workbook is recalculated. Assuming you have other formulas that cause a recalculation, your UDF should recalculate too. The code for a Workbook_Open event should go into the ThisWorkbook module of the relevant workbook. If it doesn't run from there, check your macro security settings.
 
Upvote 0

egiannaros

New Member
Joined
Mar 14, 2008
Messages
42
I have a security password set on the VBA for this file. I thought that just limits who can view and change the VBA, but will that security interfere with either method? Thanks.
 
Upvote 0

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
40,364
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
No, it shouldn't do.
 
Upvote 0

Forum statistics

Threads
1,190,782
Messages
5,982,886
Members
439,803
Latest member
sushilneupane

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