I would like to create a UDF in VBA making use of Excel's "Fourier" sub available in ATPVBAEN.XLAM Analysis ToolPack VBA. I thought a way to do this would be to create on the fly a new WorkSheet, run the sub with the output directed to that new Worksheet, copy the results into an array, delete the created worksheet, and return the array. However, I seem to have run into a problem where I cannot create a new WorkSheet in a call from a function in the workbook; a call to the following function from a cell in the workbook does not create a new worksheet:
Function addWS() As Variant
Dim WS As Worksheet
With ThisWorkbook
Set WS = .Worksheets.Add
End With
End Function
How do I overcome this?
You can't transform the ToolPack's Fourier Transform into a UDF.
You can however implement the Fourier transform in some other way.
Define a UDF in VBA (see eg this answer and the linked code .
Use the recently released Excel LAMBDA functions to define a new custom function (see eg this repository ).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.