ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Can I Assign A User Defined Function To A Cell? (https://www.excelbanter.com/excel-worksheet-functions/236524-re-can-i-assign-user-defined-function-cell.html)

smartin

Can I Assign A User Defined Function To A Cell?
 
Wayne wrote:
Can I assign a user defined function to a cell? I have the function
"=AUST_RWCFR_MAText" assigned to a textbox and it works well. However
I don't seem to be able to assign this function to a cell. I get a
#VALUE! error. How can I assign this function to a cell?



You can fire code when the user selects a certain cell. Place this code
in the /worksheet/ module:

Option Explicit

Private Sub Worksheet_SelectionChange _
(ByVal Target As Range)
' do something if user selects cell J10
If Not Application.Intersect _
(Target, Range("J10")) Is Nothing Then
DoSomething
End If
End Sub



The sub that does the real work can in any module you choose:

Public Sub DoSomething()
MsgBox "You selected J10."
End Sub


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

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