473,395 Members | 1,938 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Excel.WorksheetFunction Argument in User-Defined Function

I'd like to use the Excel.WorksheetFunction library to compute median
and percentiles in a user-defined function. Rather than creating a
SQL dataset in the function, I'd like to use the data from the calling
report as the function argument.

Example:
The report's Record Source is a query that fetches salaries from a
database, "SELECT JobID, JobTitle, BaseSalary ORDER BY JobTitle".

The report groups BaseSalary by JobTitle.

I have a textbox with Control Source of "=Avg([BaseSalary])"
I have another textbox with Control Source of "=Perc25([BaseSalary])",
where Perc25 is the custom function that calls
Excel.WorksheetFunction.Percentile

The first textbox, which uses the built-in function "Avg", correctly
computes Average using all of the BaseSalary values for that
particular JobTitle.

The second textbox only displays the value of Perc25 for the last
listed BaseSalary. Is there a way to reference the complete set of
BaseSalary values for that particular JobTitle?

Thank you for your help!
Nov 12 '05 #1
1 4404
The AVG function is a domain aggregate function builtin to Access, so it
already "knows" that every value has to be addressed.

A Custom function cannot do this, unless you can describe Perc25 as a
combination of row-level functions and aggregates (for example, calculating the
GEOMEAN is possible in Access by using the currect LOG and AVG operations)

I'm not familiar with the Perc25 function, so I'm not sure of the nature of its
argument definition. If it's like most XL functions, it either takes a range of
values, or a maximum of 30 comma-delimited values.

You may be better-off creating an equivalent function using Recordsets in
Access, passing in the JobCode, but this will be slow.

If your recordsets are large (many records per JobCode), then maybe using
automation is the way to go: Use CopyFromRecordset out to XL; put the Perc25
function at the bottom of the range; then read back that value.
Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Daniel Chartier | last post by:
Hello, all. I found a bit of code that lets me read an Excel file from and to a specifi range. See the code below. But what if I only want to specify the STARTING position and simply want it...
2
by: deko | last post by:
I use a complied query to export to Excel like this: SELECT * INTO . FROM tblExcelData; But I have a situation where I need to export several tables into the same worksheet. The idea is to...
3
by: john Hoffman | last post by:
Hello, I am using automation in C# with an Excel spreadsheet. All is well until I try to print to a printer other than the default one. I use a C# print dialog to return me the printer name to...
2
by: Kumar | last post by:
Hi Folks, I have a question regarding my windows c# application. This application just reads MS Excel file and puts the data in to sql server database. In that excel file ,it has one named cell...
7
by: Alain \Mbuna\ | last post by:
Hi everybody. In my program I have some data that is calculated after some input from the user. I have written some code that opens an Excel workbook, with 5 worksheets and the calculated data...
3
by: Tim Marsden | last post by:
Hi, I am currently creating an instance of Excel using VB.NET Automation. dim xl as Excel.Application xl = new Excel.Application However, how can I have more control over the starting of...
2
by: james | last post by:
Hi all, I am trying to convert some old VB6 code to .NET. Take this first section (there is more, but hey-ho...) Dim XLApp As Object Dim XLSheet Dim XLBook Dim HeaderItem As String Dim...
0
by: acarrazco | last post by:
Hello, I am totaly new to VBA and I'm trying to modify a macro that was given to me but it doesn't seem to be working. I'm trying to extract data from three excel spreadsheets, put it into a combined...
0
by: helraizer1 | last post by:
Hi folks, I have made a ledger sub in Excel. The task is to create a spreadsheet solution for a foreign exchange bureau so each transaction that happens it adds the details to a ledger sheet. ...
3
by: MM | last post by:
Hi to all, I'm trying to import a tab separated values file onto Excel with the following script: import csv from pyExcelerator import * w = Workbook() worksheet = w.add_sheet('sim1')
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.