View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
smartin smartin is offline
external usenet poster
 
Posts: 915
Default 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