ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Determine the current cell while inside a User Defined Function (https://www.excelbanter.com/excel-programming/352100-determine-current-cell-while-inside-user-defined-function.html)

pmax

Determine the current cell while inside a User Defined Function
 
I have a worksheet that contains User Defined Function calls in the
cells. At the time you open the sheet, the function is called and
populates the value for the cell. I am trying to determine the current
cell. When I walk through this in debug mode, it says the active column
is the last column that was active when the sheet was saved. It doesn't
refer to the current cell that has called the user defined function.
How can I determine what the cell that the user defined function is
currently updating?

My cell contains the following function:
=wbGetLastCompletedSampleDate("123","abc",QueryDat es!B8,QueryDates!B9)
When it runs the function, I need to set 2 custom document properties
for the cell that contain QueryDates!B8 & QeuryDates!B9. Whenever I
look at the activecell within the function WbGetLastCompletedSampleDate
(in runtime) it always returns the same value.

I appreciate any feedback on this issue.

Thanks.


Dave Peterson

Determine the current cell while inside a User Defined Function
 
Application.caller
is what you're looking for.

Option Explicit
Function myFunc() As String
With Application.Caller
myFunc = .Row & "--" & .Column
End With
End Function

pmax wrote:

I have a worksheet that contains User Defined Function calls in the
cells. At the time you open the sheet, the function is called and
populates the value for the cell. I am trying to determine the current
cell. When I walk through this in debug mode, it says the active column
is the last column that was active when the sheet was saved. It doesn't
refer to the current cell that has called the user defined function.
How can I determine what the cell that the user defined function is
currently updating?

My cell contains the following function:
=wbGetLastCompletedSampleDate("123","abc",QueryDat es!B8,QueryDates!B9)
When it runs the function, I need to set 2 custom document properties
for the cell that contain QueryDates!B8 & QeuryDates!B9. Whenever I
look at the activecell within the function WbGetLastCompletedSampleDate
(in runtime) it always returns the same value.

I appreciate any feedback on this issue.

Thanks.


--

Dave Peterson

pmax

Determine the current cell while inside a User Defined Function
 
Thank YOU! I searched help and looked at my books, but didn't find
that. I appreciate your help.



All times are GMT +1. The time now is 12:10 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com