Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3
Default DSUM - Modifying the function...

DSUM - Modifying the function...



I am not sure if everyone knows the DSUM function but I am trying to modify
this so the criteria and the field names are in two separate ranges.



The Syntax of the DSUM is



DSUM( table , column , criteria ) where the table is the range of all data
elements, column is the field you will like to sum and the criteria is the
range (including the field names in the table) you will like to define for
the criteria.



Criteria is where I want to change the function so the label and the
Criteria is in two different ranges. In order to define the criteria you
will first have to have the label and under the label you must define your
criteria.



Well - here is my question, Is there anyway I can combine the two arrays to
one array and send that in to the DSUM function?



This is the function I am trying to create.



Function CSUM(ByVal MyDB As Variant, ByVal MyFNToSum As Variant, ByVal
MyFields As Variant, ByVal MyCriteria As Variant) As Variant



'MyDB is the range where allof the data and fields exist

'MyFNToSum is the field name you will like to sum

'MyFields is the range where the field names exist

'MyCriteria is the array that includes tthe criteria for the sum function.



Dim MyRange As Excel.Range



MyRange = Excel.Union(MyFields, MyCriteria)



MyRange = MyCriteria



CSUM = Application.WorksheetFunction.DSum(MyDB, MyFNToSum, MyRange)



End Function



No matter what I do I keep getting "#VALUE" in my excel sheet cell. It
seems like that I touch the variable excel does not like it. I thought this
was an array but it looks like an Excel.Range object. However, that still
did not work.



ANYONE - HELP!!!!!!




  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 733
Default DSUM - Modifying the function...

DKIM wrote...
DSUM - Modifying the function...

....
Well - here is my question, Is there anyway I can combine the two arrays to
one array and send that in to the DSUM function?


No.

This is the function I am trying to create.

Function CSUM(ByVal MyDB As Variant, ByVal MyFNToSum As Variant, _
ByVal MyFields As Variant, ByVal MyCriteria As Variant) As Variant

....
Dim MyRange As Excel.Range

MyRange = Excel.Union(MyFields, MyCriteria)


This should be throwing a runtime error. You'd need to use

Set MyRange = Excel.Union(MyFields, MyCriteria)

to *set* the range variable MyRange to the union of the two ranges.
MyRange would then refer to a 2-area range. Note that *BOTH* MyFields
*AND* MyCriteria *MUST* refer to ranges IN THE SAME WORKSHEET in order
for Union to work.

MyRange = MyCriteria


This should throw another runtime error. Again you're missing Set. Even
if you'd added Set, this would be a logic error. You already set
MyRange to the union of the ranges MyFields and MyCriteria above, and
now you've replaced that with a duplicate reference to MyCriteria.

CSUM = Application.WorksheetFunction.DSum(MyDB, MyFNToSum, MyRange)


And here's where everything breaks down. The criteria argument to DSUM
must be a reference to a single area range.

End Function

....

DSUM won't do what you want. You may want to read up on Microsoft's
SQL.REQUEST add-in function.

Reply
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
Prom with the DSUM function oteixeira Excel Worksheet Functions 3 June 12th 06 04:41 PM
Criteria problems in the DSUM function AA Excel Worksheet Functions 5 January 10th 06 10:16 PM
Date & Time mully New Users to Excel 4 May 23rd 05 11:56 AM
Conversion SVC Excel Worksheet Functions 9 February 28th 05 02:29 PM
HOW CAN I GET OFFICE 2003 EXCEL BASIC TO NEST FUNCTIONS LIKE EXCE. Robert AS Excel Worksheet Functions 4 December 2nd 04 10:49 AM


All times are GMT +1. The time now is 11:18 AM.

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

About Us

"It's about Microsoft Excel"