PC Review


Reply
Thread Tools Rate Thread

Convert array formula into VBA module

 
 
Forgone
Guest
Posts: n/a
 
      30th Oct 2008
I've got an Array Formula that I want to be able to convert to a VBA
function so that I can manipulate it without having to copy and paste
the formula a large number of times through out the 800 line workbook.

The base Formula, which uses Name ranges is:

Revenue:
=SUM((ytd.ccb=VALUE(BCostCentre))*(ytd.ccc=VALUE($C19))*(ytd.ccd<>VALUE(191))*(ytd.ccd<>VALUE(999))*(ytd.act))*-1)

Expense:
=SUM((ytd.ccb=VALUE(BCostCentre))*(ytd.ccc=VALUE($C19))*(ytd.ccd<>VALUE(191))*(ytd.ccd<>VALUE(999))*(ytd.act)))


What I want to do is along the lines of....... if the values in
ytd.ccb, ytd.ccc and ytd.ccd are null then sum up everything otherwise
if there is a value, only do that value.

This is one of the formula modifications I've done.
=IF(BCostCentre="",SUM((ytd.ccc=VALUE($C19))*(ytd.ccd<>VALUE(191))*(ytd.ccd<>VALUE(999))*(ytd.act))*-1,SUM((ytd.ccb=VALUE(BCostCentre))*(ytd.ccc=VALUE($C19))*(ytd.ccd<>VALUE(191))*(ytd.ccd<>VALUE(999))*(ytd.act))*-1)

but I think it would be a lot easier to do it using a VBA function.

Ideally, I would like to use a wildcard string in those values, eg:
"***" which will tell the formula to sum all and not filter it based
on the results.

Any assistance would be appreciated.

Thanks.





 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      30th Oct 2008
I don't quite understand what you are doing. Not sure what values are names
ranges, which are integers but this code below shoiuld help you get started.

Function Revenue(ValueCenter As String, YTD_B As Single, YTD_C As Single, _
YTD_D As Single, Val1 As Variant, Val2 As Variant, Val3 As Variant, _
Actual As Single, All As Boolean)

If (YTD_C = Val(Range(ValueCenter))) And (YTD_C = Val(Val1)) And _
(YTD_D <> Val(Val2)) And (YTD_D <> Val(Val3)) Then

Revenue = -1 * Val(Actual)
End If
End Function


"Forgone" wrote:

> I've got an Array Formula that I want to be able to convert to a VBA
> function so that I can manipulate it without having to copy and paste
> the formula a large number of times through out the 800 line workbook.
>
> The base Formula, which uses Name ranges is:
>
> Revenue:
> =SUM((ytd.ccb=VALUE(BCostCentre))*(ytd.ccc=VALUE($C19))*(ytd.ccd<>VALUE(191))*(ytd.ccd<>VALUE(999))*(ytd.act))*-1)
>
> Expense:
> =SUM((ytd.ccb=VALUE(BCostCentre))*(ytd.ccc=VALUE($C19))*(ytd.ccd<>VALUE(191))*(ytd.ccd<>VALUE(999))*(ytd.act)))
>
>
> What I want to do is along the lines of....... if the values in
> ytd.ccb, ytd.ccc and ytd.ccd are null then sum up everything otherwise
> if there is a value, only do that value.
>
> This is one of the formula modifications I've done.
> =IF(BCostCentre="",SUM((ytd.ccc=VALUE($C19))*(ytd.ccd<>VALUE(191))*(ytd.ccd<>VALUE(999))*(ytd.act))*-1,SUM((ytd.ccb=VALUE(BCostCentre))*(ytd.ccc=VALUE($C19))*(ytd.ccd<>VALUE(191))*(ytd.ccd<>VALUE(999))*(ytd.act))*-1)
>
> but I think it would be a lot easier to do it using a VBA function.
>
> Ideally, I would like to use a wildcard string in those values, eg:
> "***" which will tell the formula to sum all and not filter it based
> on the results.
>
> Any assistance would be appreciated.
>
> Thanks.
>
>
>
>
>
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      30th Oct 2008
First, I'm not sure why you use =value() around your terms. It may make sense
for cells that may not be numeric, but 191 and 999 are already numbers, so it's
not necessary/useful there.

Second, you have a couple of choices to convert the array formula into VBA.

#1. Loop through each of the cells and accumulate the total.
#2. Use Evaluate.

dim mySum as double
mysum = worksheets("Sheet999").evaluate("SUM((ytd.ccb=VALUE(BCostCentre))" _
& "*(ytd.ccc=VALUE($C19))" _
& "*(ytd.ccd<>191)" _
& "*(ytd.ccd<>999)" _
& "*(ytd.act))*-1)")



Forgone wrote:
>
> I've got an Array Formula that I want to be able to convert to a VBA
> function so that I can manipulate it without having to copy and paste
> the formula a large number of times through out the 800 line workbook.
>
> The base Formula, which uses Name ranges is:
>
> Revenue:
> =SUM((ytd.ccb=VALUE(BCostCentre))*(ytd.ccc=VALUE($C19))*(ytd.ccd<>VALUE(191))*(ytd.ccd<>VALUE(999))*(ytd.act))*-1)
>
> Expense:
> =SUM((ytd.ccb=VALUE(BCostCentre))*(ytd.ccc=VALUE($C19))*(ytd.ccd<>VALUE(191))*(ytd.ccd<>VALUE(999))*(ytd.act)))
>
> What I want to do is along the lines of....... if the values in
> ytd.ccb, ytd.ccc and ytd.ccd are null then sum up everything otherwise
> if there is a value, only do that value.
>
> This is one of the formula modifications I've done.
> =IF(BCostCentre="",SUM((ytd.ccc=VALUE($C19))*(ytd.ccd<>VALUE(191))*(ytd.ccd<>VALUE(999))*(ytd.act))*-1,SUM((ytd.ccb=VALUE(BCostCentre))*(ytd.ccc=VALUE($C19))*(ytd.ccd<>VALUE(191))*(ytd.ccd<>VALUE(999))*(ytd.act))*-1)
>
> but I think it would be a lot easier to do it using a VBA function.
>
> Ideally, I would like to use a wildcard string in those values, eg:
> "***" which will tell the formula to sum all and not filter it based
> on the results.
>
> Any assistance would be appreciated.
>
> Thanks.


--

Dave Peterson
 
Reply With Quote
 
Forgone
Guest
Posts: n/a
 
      31st Oct 2008
> First, I'm not sure why you use =value() around your terms. *It may make sense
> for cells that may not be numeric, but 191 and 999 are already numbers, so it's
> not necessary/useful there.


I've since removed the 191 and 999 and converted it to
ytd.ccd=VALUE(rep.fund)

I have had to use value because the cells that is being used as the
search parameters is formatted as text intentionally.

The worksheet is setup so that the search parameters are in the top of
the worksheet which I've named.
BCostCentre | BFund | BEntity | BProject - this is where the user can
input the search parameters if they want to restrict it to a certain
business area or project.

The named ranges: ytd.cca | ytd.ccb | ytd.ccc | ytd.ccd | ytd.cce is
the main datasource table for and are the relevant costcodes.
YTD represents the datasource for "year to date" thus ytd.act = year
to date actuals

BEntity = CCA
BCostCentre = CCB
BFund = CCC
BAccount (not used) = CCD
BProject = CCE

The reference to $C19 is the specific account code (CCD)

I have a number of data sources.

YTD for Year To Date Actuals which gets updated every month
O9B for 2008/2009 Budget
O8B for 2007/2008 Budget
O8A for 2007/2008 Actuals

I'm trying to keep a consistency with the named ranges.

What I've had to do is if I wanted to look at the entire Department as
a whole, I've had to create another worksheet and manipulate the
formulas to suit but that means on a very old system (which I'm using
at work) takes a very long time to calculate. I would like to work on
the one worksheet.

At the end, I only want to use the one worksheet and either report on
the required values (if not null then ...... report on each criterion
if applicable) or if null then report on the lot.
 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      31st Oct 2008
Does this mean that the Evaluate function worked?

If you're having trouble, get the array formula working in a cell on the
worksheet. Then post that working formula.

Forgone wrote:
>
> > First, I'm not sure why you use =value() around your terms. It may make sense
> > for cells that may not be numeric, but 191 and 999 are already numbers, so it's
> > not necessary/useful there.

>
> I've since removed the 191 and 999 and converted it to
> ytd.ccd=VALUE(rep.fund)
>
> I have had to use value because the cells that is being used as the
> search parameters is formatted as text intentionally.
>
> The worksheet is setup so that the search parameters are in the top of
> the worksheet which I've named.
> BCostCentre | BFund | BEntity | BProject - this is where the user can
> input the search parameters if they want to restrict it to a certain
> business area or project.
>
> The named ranges: ytd.cca | ytd.ccb | ytd.ccc | ytd.ccd | ytd.cce is
> the main datasource table for and are the relevant costcodes.
> YTD represents the datasource for "year to date" thus ytd.act = year
> to date actuals
>
> BEntity = CCA
> BCostCentre = CCB
> BFund = CCC
> BAccount (not used) = CCD
> BProject = CCE
>
> The reference to $C19 is the specific account code (CCD)
>
> I have a number of data sources.
>
> YTD for Year To Date Actuals which gets updated every month
> O9B for 2008/2009 Budget
> O8B for 2007/2008 Budget
> O8A for 2007/2008 Actuals
>
> I'm trying to keep a consistency with the named ranges.
>
> What I've had to do is if I wanted to look at the entire Department as
> a whole, I've had to create another worksheet and manipulate the
> formulas to suit but that means on a very old system (which I'm using
> at work) takes a very long time to calculate. I would like to work on
> the one worksheet.
>
> At the end, I only want to use the one worksheet and either report on
> the required values (if not null then ...... report on each criterion
> if applicable) or if null then report on the lot.


--

Dave Peterson
 
Reply With Quote
 
Forgone
Guest
Posts: n/a
 
      3rd Nov 2008
On Oct 31, 9:22*pm, Dave Peterson <peter...@verizonXSPAM.net> wrote:
> Does this mean that the Evaluate function worked?
>


I tried it, and it doesn't appear to be working at all.
This is the entire function that works.

{=IF(BCostCentre="",SUM((ytd.ccc=VALUE($C19))*(ytd.ccd=VALUE(rep.fund))*(ytd.act)),SUM((ytd.ccb=VALUE(BCostCentre))*(ytd.ccc=VALUE($C19))*(ytd.ccd=VALUE(rep.fund))*(ytd.act)))}

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      3rd Nov 2008
Maybe...
dim res as variant
dim myFormula as string

myformula = "IF(BCostCentre="""",SUM((ytd.ccc=VALUE($C19))" _
& "*(ytd.ccd=VALUE(rep.fund))*(ytd.act))," _
& "SUM((ytd.ccb=VALUE(BCostCentre))*(ytd.ccc=VALUE($C19))", _
& "*(ytd.ccd=VALUE(rep.fund))*(ytd.act)))"

res = worksheets("somesheetnamehere").evaluate(myformula)

(Untested.)

If that doesn't work, share that snippet of code.

Forgone wrote:
>
> On Oct 31, 9:22 pm, Dave Peterson <peter...@verizonXSPAM.net> wrote:
> > Does this mean that the Evaluate function worked?
> >

>
> I tried it, and it doesn't appear to be working at all.
> This is the entire function that works.
>
> {=IF(BCostCentre="",SUM((ytd.ccc=VALUE($C19))*(ytd.ccd=VALUE(rep.fund))*(ytd.act)),SUM((ytd.ccb=VALUE(BCostCentre))*(ytd.ccc=VALUE($C19))*(ytd.ccd=VALUE(rep.fund))*(ytd.act)))}


--

Dave Peterson
 
Reply With Quote
 
Forgone
Guest
Posts: n/a
 
      3rd Nov 2008
I tried using the worksheet version Tools > Formula Auditing >
Evaluate - it passes the first condition ({=IF(BCostCentre="",) which
works but excel dies when it moves on.


I'll try it and see how it works.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
complex excel formula Array how do I convert it to a vba Function =?Utf-8?B?Um9i?= Microsoft Excel Worksheet Functions 1 10th Apr 2006 07:06 PM
Convert Normal formula to array formula =?Utf-8?B?UHJhZGlwIEphaW4=?= Microsoft Excel Programming 4 23rd May 2005 04:32 PM
Convert Chart Series Formula to Array Via VBA? Kevin G Microsoft Excel Programming 1 6th May 2004 05:13 AM
Convert Chart Series Formula to Array Via VBA? Kevin G Microsoft Excel Charting 1 5th May 2004 04:52 AM
Convert Text string to Array Formula Steve Schlesinger Microsoft Excel Discussion 0 8th Aug 2003 08:19 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:37 AM.