JenniferMurphy
Well-known Member
- Joined
- Jul 23, 2011
- Messages
- 2,687
- Office Version
- 365
- Platform
- Windows
I am working on a UDF that processes a large table of data. If it detects an error, I would like it to make that the active cell on return to the sheet. Here's my code that isn't working. I've simplified the code, but I think all the relevant parts are included. The statement in question is the next to last one.
Can someone suggest a working solution?
Code:
Public Function MyFun(Data as Range) As Variant
Dim errmsg As String
Dim RngColBeg As Long
Dim RngColEnd As Long
RngColBeg = 1
RngColEnd = Data.Columns.Count
Dim iCol As Long
Dim CellAddr As String
For iCol = RngColBeg To RngColEnd
CellAddr= Data(1, iCol).Address
. . .
If (some error occurs) Then
errmsg = "...text of error message..."
MyFun = ErrCode(errmsg,CellAddr): Exit Function
End If
. . .
Next iCol
. . .
End Function
Public Function ErrCode(errtxt as string, celladdr as string) As Variant
. . .
Dim errmsg as string
errmsg = (standard error message including the cell address)
Dim Button As Long
Button = MsgBox(errmsg, vbYesNoCancel + vbDefaultButton2)
. . .
ErrCode = (some error code)
ActiveSheet.Range(pErrCellAddr).Select
End Function
Can someone suggest a working solution?