How can I change a cell value inside a VB function

renatoab

New Member
Joined
Jun 14, 2009
Messages
32
I have a function wich is called in a cell.
When the function find some problem, I want to register the error in another sheet at the same file, as a log. But when I'm into the function, I'm not able to set values to other cells, a runtime error occur.

Even if I make a separate Sub, the same occurs.
Running the sub separately, it works, but when it is called by the function, it doesn't work.

How can I do this? I want to store the informations about the functions' errors, but I don't want to use an external file, because it will become slow.

Thanks in advance
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
A way to do could be ( a bit long):
Have a variable as global where is stored the error code
Code:
Global ERROR_Check
In the code for the sheet (sheet1) where is the function, use
Code:
Private Sub Worksheet_Calculate()
    Call ESSAI
End Sub
In the subroutine ESSAI store the error code
Code:
Sub ESSAI()
    Sheets("Sheet2").Cells(2, 2) = ERROR_Check
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,539
Members
449,088
Latest member
RandomExceller01

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