Why does my macro keep calling my UDF?

ransomedbyfire

Board Regular
Joined
Mar 9, 2011
Messages
121
I am writing a few macros and UDFs in the same workbook. My UDFs are all in Module 1, and my macros are in their relevant sheets. When I run one of my macros, it jumps into the UDFs once it reads this line:
Code:
    Selection.Formula = Cells(13, c).Formula

(The formula in row 13 is "=IF(N13<>"",RANK(N13,$N$8:$N$12),"")". This has nothing to do with my UDFs.)

Why is this, and what can I do to stop it from happening?

Thanks!
 
Last edited:

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
UDFs are not allowed to make changes to sheet like coloring, deleting etc. In your case this is what you do. UDF can only return a scalar value or array. Anyway, that's why you write UDF - to get some value. If you want your code to run, make it Sub.
 
Upvote 0
It may be that the worksheet is simply triggering a recalculation because of a change in a dependent cell. That's normal behavior for many formulas, UDF or otherwise.

ξ
 
Upvote 0
Thanks, Xenou. I realized that's what was going on last night. So, I wrote a few lines that set calculation to manual and that manually calculate the sheet when I want it to be done, not when Excel does.
 
Upvote 0
Also, it is very rare that you need to Select a cell to work with it in VBA. You can work with ranges directly.

i.e.

Code:
Range("A1").Formula=Cells(13, c).Formula
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,277
Members
452,902
Latest member
Knuddeluff

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