Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 41
Default Macro to Sum Arrays of Various Size

I have about 1500 sets of data in a single column that I need to sum,
individually.

Example

Product A $500
Product A $200
Product A $150

Product B $200
Product B $100

I can write a macro that searches for the empty cell (below $150 for Product
A and below $100 for product B), and I could then use the sum function; but
in one case I'm summing 3 terms, in the second case, I'm summing 2. I don't
know how to "tell the macro" (I'm assuming it's a relative reference macro),
how to determine the number of terms to sum.

Thanks, as always....
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,593
Default Macro to Sum Arrays of Various Size

Sans VBA?

In C1, enter

=IF(A2="",SUM(INDEX(B:B,MAX(1,MAX(IF($A$1:A1="",RO W($A$1:A1))))):A1),"")

and copy down.

which is an array formula, it should be committed with Ctrl-Shift-Enter, not
just Enter.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"ConfusedNHouston" wrote in
message ...
I have about 1500 sets of data in a single column that I need to sum,
individually.

Example

Product A $500
Product A $200
Product A $150

Product B $200
Product B $100

I can write a macro that searches for the empty cell (below $150 for

Product
A and below $100 for product B), and I could then use the sum function;

but
in one case I'm summing 3 terms, in the second case, I'm summing 2. I

don't
know how to "tell the macro" (I'm assuming it's a relative reference

macro),
how to determine the number of terms to sum.

Thanks, as always....



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 41
Default Macro to Sum Arrays of Various Size

i don't understand the part about "committing" with the Ctrl + Shft + Enter.
I copied the argument into C1 and dragged it down through two sets of data.
At the end of the first set, it gave me an accurate sum of the values
associated with the independent variable (product name). At the end of the
second set of product names, it returned a running sum; the sum of the first
set of products plus the sum for the second set of products - basically a
running grand total for the spreadsheet.

I've checked the syntax and I wrote the statement exactly as you did above.

Was this statement supposed to go into a macro? I just wrote it and pasted
it into column C.

What am I missing? Thanks....



"Bob Phillips" wrote:

Sans VBA?

In C1, enter

=IF(A2="",SUM(INDEX(B:B,MAX(1,MAX(IF($A$1:A1="",RO W($A$1:A1))))):A1),"")

and copy down.

which is an array formula, it should be committed with Ctrl-Shift-Enter, not
just Enter.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"ConfusedNHouston" wrote in
message ...
I have about 1500 sets of data in a single column that I need to sum,
individually.

Example

Product A $500
Product A $200
Product A $150

Product B $200
Product B $100

I can write a macro that searches for the empty cell (below $150 for

Product
A and below $100 for product B), and I could then use the sum function;

but
in one case I'm summing 3 terms, in the second case, I'm summing 2. I

don't
know how to "tell the macro" (I'm assuming it's a relative reference

macro),
how to determine the number of terms to sum.

Thanks, as always....




  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,593
Default Macro to Sum Arrays of Various Size

Enter the formula in C 1, and instead of hitting Enter to finish the
formula, use Ctrl-Shift-Enter all together. Then drag-copy it down.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"ConfusedNHouston" wrote in
message ...
i don't understand the part about "committing" with the Ctrl + Shft +

Enter.
I copied the argument into C1 and dragged it down through two sets of

data.
At the end of the first set, it gave me an accurate sum of the values
associated with the independent variable (product name). At the end of

the
second set of product names, it returned a running sum; the sum of the

first
set of products plus the sum for the second set of products - basically a
running grand total for the spreadsheet.

I've checked the syntax and I wrote the statement exactly as you did

above.

Was this statement supposed to go into a macro? I just wrote it and

pasted
it into column C.

What am I missing? Thanks....



"Bob Phillips" wrote:

Sans VBA?

In C1, enter

=IF(A2="",SUM(INDEX(B:B,MAX(1,MAX(IF($A$1:A1="",RO W($A$1:A1))))):A1),"")

and copy down.

which is an array formula, it should be committed with Ctrl-Shift-Enter,

not
just Enter.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"ConfusedNHouston" wrote in
message ...
I have about 1500 sets of data in a single column that I need to sum,
individually.

Example

Product A $500
Product A $200
Product A $150

Product B $200
Product B $100

I can write a macro that searches for the empty cell (below $150 for

Product
A and below $100 for product B), and I could then use the sum

function;
but
in one case I'm summing 3 terms, in the second case, I'm summing 2. I

don't
know how to "tell the macro" (I'm assuming it's a relative reference

macro),
how to determine the number of terms to sum.

Thanks, as always....






  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,441
Default Macro to Sum Arrays of Various Size

Houston,

Take out the spaces and use a pivot table.

Or use a macro like this, to enter the sums in column B:

Sub EnterSums()
Dim myArea As Range

For Each myArea In Range("B:B").SpecialCells(xlCellTypeConstants).Are as
myArea.Cells(myArea.Cells.Count + 1).Formula = "=SUM(" & myArea.Address & ")"
Next myArea
End Sub

HTH,
Bernie
MS Excel MVP


"ConfusedNHouston" wrote in message
...
I have about 1500 sets of data in a single column that I need to sum,
individually.

Example

Product A $500
Product A $200
Product A $150

Product B $200
Product B $100

I can write a macro that searches for the empty cell (below $150 for Product
A and below $100 for product B), and I could then use the sum function; but
in one case I'm summing 3 terms, in the second case, I'm summing 2. I don't
know how to "tell the macro" (I'm assuming it's a relative reference macro),
how to determine the number of terms to sum.

Thanks, as always....





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
how do I email amacro? leo Excel Worksheet Functions 24 August 9th 06 02:47 PM
How to stop Excel remembering/loading macro from previously opened Workbook Norman Yuan Excel Discussion (Misc queries) 4 June 17th 06 04:13 PM
Macro Help In Excel welshlad Excel Discussion (Misc queries) 14 October 26th 05 02:34 PM
Closing File Error jcliquidtension Excel Discussion (Misc queries) 4 October 20th 05 12:22 PM
Highlight Range - wrong macro, please edit. Danny Excel Worksheet Functions 8 October 19th 05 11:11 PM


All times are GMT +1. The time now is 03:04 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"