LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 7
Default User Defined Function Syntax

Hello,

I am new to UDF and VBA. I have this small function here, could you please
provide me the corrected syntax? This UDF should allow me to use any Excel
model (collection of cells linked with each other through a chain of
formulas, starting with some input cells and ending with a result cell) as a
function.

Thanks.

Function XLModel(Name As String, InputValueCells As Range, ModelInputCells
As Range, ModelOutputCell As Range)
'Converts any Excel model into a function

'If the values to be plugged in don't map to the model inputs, show
error message
If (InputValueCells.Areas.Count < ModelInputCells.Areas.Count) Then
XLModel = "Error: Select same number of cells in InputValueCells and
ModelInputCells"
End If

'Temporarily hold existing input values of the model
DIM TempArray As String[InputValueCells.Areas.Count]


'Run through all the cells of values to be plugged in the model
For i = 1 To InputValueCells.Areas.Count
TempArray [i] = ModelInputCells.Cells[i]

'Plug in the values into the model input
ModelInputCells.cells[i] = InputValueCells.cells[i]
Next i

'Pick up the model output value
ResultValue = ModelOutputCell.Value

'Reset the model input values to what they were originally
For i = 1 To InputValueCells.Areas.Count
ModelInputCells.cells[i] = TempArray[i]
Next i

XLModel = ResultValue

End Function


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
User defined functions without using VBA. [email protected] Excel Discussion (Misc queries) 0 June 13th 06 05:50 PM
Custom functions calculating time arguments Help Desperate Bill_De Excel Worksheet Functions 12 April 25th 06 02:22 AM
Getting Yahoo Stock Quotes by a USer Defined Function MS Office Excel Worksheet Functions 1 September 8th 05 05:08 AM
Date & Time mully New Users to Excel 4 May 23rd 05 11:56 AM
how to move user defined function Grant Excel Worksheet Functions 1 November 17th 04 06:38 PM


All times are GMT +1. The time now is 06:17 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"