0

i have search in excel an amplitude min max function that should be like that :

      myCell = Amplitude(Table1[varType])

that return immediatly amplitude of desired column .

All of this without creating a cell Max and min and doing like myCell = max-min

Noj
  • 164
  • 1
  • 15

1 Answers1

1

You can easily create such a function (UDF)

In a standard module enter:

Public Function span(rIn As Range) As Variant
    Dim wf As WorksheetFunction
    Set wf = Application.WorksheetFunction
    span = wf.Max(rIn) - wf.Min(rIn)
End Function

User Defined Functions (UDFs) are very easy to install and use:

  1. ALT-F11 brings up the VBE window
  2. ALT-I ALT-M opens a fresh module
  3. paste the stuff in and close the VBE window

If you save the workbook, the UDF will be saved with it. If you are using a version of Excel later then 2003, you must save the file as .xlsm rather than .xlsx

To remove the UDF:

  1. bring up the VBE window as above
  2. clear the code out
  3. close the VBE window

To use the UDF from Excel:

=span(A:A)

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

and

http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx

and for specifics on UDFs, see:

http://www.cpearson.com/excel/WritingFunctionsInVBA.aspx

Macros must be enabled for this to work!

Community
  • 1
  • 1
Gary's Student
  • 95,722
  • 10
  • 59
  • 99