View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Mark[_21_] Mark[_21_] is offline
external usenet poster
 
Posts: 3
Default Calling Add-in functions from VBA

Ronald,

Thanks for that info it's very helpful.

With regard to my problem passing objects between add-ins, I have
rewritten the function in question so that it does not use the
Worksheet.Find method and it now works. Ofcourse, it's still an
unsatisfactory outcome but I think this is an Excel experience I will
use to guide me in the future.

Here's the code in case you are interested:

Public Function rngOp02_IdentifyLastCell(ws As Worksheet) As Range
'Author: Mark Townsend
'Date: 12-09-2003
'Purpose: To identify the last cell in a range.
'Comment: The range need not be contiguous, _
it is really the intersection of the _
last row and last column in all the _
ranges used in a worksheet.
'Arguments: The worksheet object in question.
'Returns: A range object that is the final row _
and final column.

Dim rngLastCell As Range
Dim rngFirstCell As Range
Dim lLastRow As Long
Dim iLastCol As Integer
Dim aData As Variant
Dim iCounter As Integer

'Initialise variables.
Set rngFirstCell = ws.UsedRange
lLastRow = rngFirstCell.Rows.Count
iLastCol = rngFirstCell.Columns.Count

'Get the real last column
Do While iLastCol 0
aData = ws.Range(Cells(1, iLastCol), Cells(lLastRow,
iLastCol)).Value
For iCounter = 1 To UBound(aData, 1)
If (Not (IsEmpty(aData(iCounter, 1)))) Then Exit Do
Next iCounter
iLastCol = iLastCol - 1
Loop

'Get the real last row.
Do While lLastRow 0
aData = ws.Range(Cells(lLastRow, 1), Cells(lLastRow,
iLastCol)).Value
For iCounter = 1 To UBound(aData, 2)
If (Not (IsEmpty(aData(1, iCounter)))) Then Exit Do
Next iCounter
lLastRow = lLastRow - 1
Loop

Set rngLastCell = ws.Range("A1").Offset(lLastRow - 1, _
iLastCol - 1)

'Return statement
Set rngOp02_IdentifyLastCell = rngLastCell

End Function

Thanks again,

Mark