Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 49948

How to prevent VBA function calls from reevaluting when worksheet opens up

$
0
0
I have some VBA functions which print a string on the cell from where it's called.

For e.g.

Code:

Public Function PrintStuff() As String

        Val1 = Application.ThisCell.Offset(0, -3)
        Val2 = Application.ThisCell.Offset(-1, -3)

        If (Val1 < Val2) Then
                PrintStuff = "Lesser"
        Else
                IsDirRevd = "Not Lesser"
        End If
 
End Function

Now let's say I call this from Cell A1 as "=PrintStuff()", then you see either Lesser or Not Lesser in Cell A1

Now I call this function & other similar functions many, many times in my worksheet.

What I want is that once the function call is evaluated & something is written on to the cell, it becomes permanent. i.e. it doesn't reevaluate the function everytime the sheet is opened - is this possible

Why I want this is because sometimes when I reopen the sheet, Lesser gets changed to Not Lesser & vice versa. This is inspite of the cells which the function checks not changing. I clear out the formula call from the cell, & rewrite the call, the string goes back to what was originally being printed.

So is there a way to freeze the output of a VBA function call?

Viewing all articles
Browse latest Browse all 49948

Trending Articles