Problem with VB function

cpu97

Board Regular
Joined
Jan 8, 2010
Messages
69
Hello,

I have an excel worksheet which calls a function. The function evaluates the arguments passed to it by cell in the spreadsheet, and then, depending on the result, places a timestamp in a cell adjacent to the one that made the call. However, I am getting a #VALUE error. Stepping through, the error occurs when the function attempts to place a value in the adjacent cell. Perhaps this is not something that can be done by a function. Can anyone confirm this? Is there a way to do this with a function? I could do it with a macro but it's a dynamic spreadsheet with other macros running at set intervals. Many thanks!

Code:
Public Function Timestamp(Curr As Integer, Prev As Integer, row As Integer, ptime As Double)
If Curr = 0 And Prev <> 0 Then
    If ptime <> 0 Then
        If Now - ptime >= (0.5 / 24) Then
            Sheets("Signals").Cells(row, 5).Value = Now
            Timestamp = 1
        End If
    Else
        Timestamp = 1
        Sheets("Signals").Cells(row, 5).Value = Now
        
    End If
Else
    Timestamp = 0
End If
End Function
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Can anyone confirm this?
With few exceptions (and this isn't one), a user-defined function can't do anything except return a value to the cell in which it appears.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,286
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