Hi all,
I’ve got an Excel workbook in which I want to use a UDF to test whether the calling cell falls within a particular named range and, if not, add the cell’s address to the named range. I can do this quite OK using the Sub ‘CellFormat’ below, but the Function ‘Fmt’ fails to update the named range and no error message is generated:
Sub CellFormat()
If Intersect(Selection, ActiveSheet.Range("Fmt1")) Is Nothing Then _
ActiveWorkbook.Names.Add Name:=" Fmt1", _
RefersTo:=ActiveWorkbook.Names.Item("Fmt1") & "," & Selection.Address
End Sub
Function Fmt(ByVal Num As Long) As Long
If Intersect(Selection, ActiveSheet.Range("Fmt1")) Is Nothing Then _
ActiveWorkbook.Names.Add Name:=" Fmt1", _
RefersTo:=ActiveWorkbook.Names.Item("Fmt1") & "," & Selection.Address
Fmt = Num
End Function
Is this possible? Any ideas where I’m going wrong?
Cheers,
Paul Edstein
[Fmr MS MVP - Word]