Modify Arrays (not using VBA)

djje87

New Member
Joined
Jun 16, 2011
Messages
4
Hi,

I'm a long time reader, first time poster, so please forgive me if I haven't done this correctly.

I have an array in Excel, that was generated by the Frequency function. I'm wondering if it is possible to modify this array using Excel functions?

In particular, I either want to remove the last element, so {1;2;3;4} becomes {1;2;3} or add an element to the end, so {1,2,3} becomes {1,2,3,4}.


Perhaps if I describe my problem, someone could suggest an alternative solution;

I have two columns of data that are in a table, one contains a reference number (the same reference number could be duplicated several times in the column), the second a price against that reference. I want to sum the prices, but not include prices that are against a duplicated reference number. So for example if I have;

AAA 5
BBB 3
AAA 2
CCC 4

The result would be 12 (= 5+3+4).

I've managed to create an array corresponding to the reference number column that has a 1 if it is the first time the reference number has occured , or a zero if not. So on the above example I would have (1,1,0,1). However, this isn't exactly what I've got, as this array is created by the Frequency function, so has one more element than this. So I actually have (1,1,0,1,0). If I could remove the last element of this array, I could use SumProduct with the price array to get my answer. Or I could add a 0 to the end of the price array. Im using a Structure Reference (MyTable[Prices]) for the price array, as the length of this column changes.

I'd ideally like this to be done without VBA, but if it's not possible, a VBA solution would be better than no solution.


Many thanks,
Dan.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Let A2:B5 house the sample you posted...

Control+shift+enter, not just enter:

=SUM(IF(FREQUENCY(IF(A2:A5<>"",MATCH("~"&A2:A5,A2:A5&"",0)),ROW(A2:A5)-ROW($A$2)+1),B2:B5))
 
Upvote 0
WOW! Thanks for that. It has been driving me crazy all day! Just one more thing, ideally I'd like to use structured references for the ranges, so A2:A5 would be MyTable[Ref], and B2:B5 MyTable[Price]. The formula works fine with these, with the excpetion of the "Row(A2)" near the end.

Is there a way of refering to the first element in my structured array? Something like MyTable[Ref](1) ? If not I can use A2, it would just be convenient if I could use the Structure Reference as I may have to rearrange the order of my columns.

Once again, many thanks for that.
 
Upvote 0
WOW! Thanks for that. It has been driving me crazy all day! Just one more thing, ideally I'd like to use structured references for the ranges, so A2:A5 would be MyTable[Ref], and B2:B5 MyTable[Price]. The formula works fine with these, with the excpetion of the "Row(A2)" near the end.

Is there a way of refering to the first element in my structured array? Something like MyTable[Ref](1) ? If not I can use A2, it would just be convenient if I could use the Structure Reference as I may have to rearrange the order of my columns.

<TABLE style="WIDTH: 192pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=256><COLGROUP><COL style="WIDTH: 48pt" span=4 width=64><TBODY><TR style="HEIGHT: 14.4pt" height=19><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; FONT-STYLE: italic; WIDTH: 48pt; FONT-FAMILY: Calibri; BACKGROUND: #4f81bd; HEIGHT: 14.4pt; COLOR: white; FONT-SIZE: 11pt; BORDER-TOP: windowtext 0.5pt solid; FONT-WEIGHT: 700; BORDER-RIGHT: windowtext 0.5pt solid; TEXT-DECORATION: none; text-underline-style: none; text-line-through: none; mso-pattern: #4F81BD none" class=xl65 height=19 width=64>Field-1</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; FONT-STYLE: italic; WIDTH: 48pt; FONT-FAMILY: Calibri; BACKGROUND: #4f81bd; COLOR: white; FONT-SIZE: 11pt; BORDER-TOP: windowtext 0.5pt solid; FONT-WEIGHT: 700; BORDER-RIGHT: windowtext 0.5pt solid; TEXT-DECORATION: none; text-underline-style: none; text-line-through: none; mso-pattern: #4F81BD none" id=td_post_2755424 class=xl65 width=64>Field-2</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; WIDTH: 48pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl66 width=64> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; WIDTH: 48pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl66 width=64> </TD></TR><TR style="HEIGHT: 14.4pt" height=19><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; FONT-FAMILY: Verdana; BACKGROUND: #dce6f1; HEIGHT: 14.4pt; COLOR: black; FONT-SIZE: 10pt; BORDER-TOP: windowtext 0.5pt solid; FONT-WEIGHT: 400; BORDER-RIGHT: windowtext 0.5pt solid; TEXT-DECORATION: none; text-underline-style: none; text-line-through: none; mso-pattern: #DCE6F1 none" class=xl67 height=19>AAA</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; FONT-FAMILY: Calibri; BACKGROUND: #dce6f1; COLOR: black; FONT-SIZE: 11pt; BORDER-TOP: windowtext 0.5pt solid; FONT-WEIGHT: 400; BORDER-RIGHT: windowtext 0.5pt solid; TEXT-DECORATION: none; text-underline-style: none; text-line-through: none; mso-pattern: #DCE6F1 none" class=xl66 align=right>5</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl66> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl66 align=right>12</TD></TR><TR style="HEIGHT: 14.4pt" height=19><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; HEIGHT: 14.4pt; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl67 height=19>BBB</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; FONT-FAMILY: Calibri; COLOR: black; FONT-SIZE: 11pt; BORDER-TOP: windowtext 0.5pt solid; FONT-WEIGHT: 400; BORDER-RIGHT: windowtext 0.5pt solid; TEXT-DECORATION: none; text-underline-style: none; text-line-through: none" class=xl66 align=right>3</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl66> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl66> </TD></TR><TR style="HEIGHT: 14.4pt" height=19><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; FONT-FAMILY: Verdana; BACKGROUND: #dce6f1; HEIGHT: 14.4pt; COLOR: black; FONT-SIZE: 10pt; BORDER-TOP: windowtext 0.5pt solid; FONT-WEIGHT: 400; BORDER-RIGHT: windowtext 0.5pt solid; TEXT-DECORATION: none; text-underline-style: none; text-line-through: none; mso-pattern: #DCE6F1 none" class=xl67 height=19>AAA</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; FONT-FAMILY: Calibri; BACKGROUND: #dce6f1; COLOR: black; FONT-SIZE: 11pt; BORDER-TOP: windowtext 0.5pt solid; FONT-WEIGHT: 400; BORDER-RIGHT: windowtext 0.5pt solid; TEXT-DECORATION: none; text-underline-style: none; text-line-through: none; mso-pattern: #DCE6F1 none" class=xl66 align=right>2</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl66> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl66> </TD></TR><TR style="HEIGHT: 14.4pt" height=19><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; HEIGHT: 14.4pt; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl67 height=19>CCC</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; FONT-FAMILY: Calibri; COLOR: black; FONT-SIZE: 11pt; BORDER-TOP: windowtext 0.5pt solid; FONT-WEIGHT: 400; BORDER-RIGHT: windowtext 0.5pt solid; TEXT-DECORATION: none; text-underline-style: none; text-line-through: none" class=xl66 align=right>4</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl66> </TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl66> </TD></TR></TBODY></TABLE>

D2, control+shift+enter, not just enter:

=SUM(IF(FREQUENCY(IF(Table1[Field-1]<>"",MATCH("~"&Table1[Field-1],Table1[Field-1]&"",0)),ROW(Table1[Field-1])-MIN(ROW(Table1[Field-1]))+1),Table1[Field-2]))

Note the call on MIN...

Once again, many thanks for that.

You are welcome. Thanks for providing feedback.
 
Upvote 0
Problem solved!

I'll now spend the next 10 hours trying to figure out how that works! It's definately going to come in useful for this project I'm doing.

Thanks one more time.
 
Upvote 0
Hi,

I'm a long time reader, first time poster, so please forgive me if I haven't done this correctly.

I have an array in Excel, that was generated by the Frequency function. I'm wondering if it is possible to modify this array using Excel functions?

In particular, I either want to remove the last element, so {1;2;3;4} becomes {1;2;3} or add an element to the end, so {1,2,3} becomes {1,2,3,4}.


Perhaps if I describe my problem, someone could suggest an alternative solution;

I have two columns of data that are in a table, one contains a reference number (the same reference number could be duplicated several times in the column), the second a price against that reference. I want to sum the prices, but not include prices that are against a duplicated reference number. So for example if I have;

AAA 5
BBB 3
AAA 2
CCC 4

The result would be 12 (= 5+3+4).

I've managed to create an array corresponding to the reference number column that has a 1 if it is the first time the reference number has occured , or a zero if not. So on the above example I would have (1,1,0,1). However, this isn't exactly what I've got, as this array is created by the Frequency function, so has one more element than this. So I actually have (1,1,0,1,0). If I could remove the last element of this array, I could use SumProduct with the price array to get my answer. Or I could add a 0 to the end of the price array. Im using a Structure Reference (MyTable[Prices]) for the price array, as the length of this column changes.

I'd ideally like this to be done without VBA, but if it's not possible, a VBA solution would be better than no solution.


Many thanks,
Dan.
Try this...

Book1
ABCD
2AAA5_12
3BBB3__
4AAA2__
5CCC4__
Sheet1

This array formula** entered in D2:

=SUM(IF(FREQUENCY(MATCH(A2:A5,A2:A5,0),ROW(A2:A5)-ROW(A2)+1),B2:B5))

** array formulas need to be entered using the key
combination of CTRL,SHIFT,ENTER (not just ENTER).
Hold down both the CTRL key and the SHIFT key
then hit ENTER.

Assumes no empty cells within the data range of column A.
 
Upvote 0
Problem solved!

I'll now spend the next 10 hours trying to figure out how that works! It's definately going to come in useful for this project I'm doing.

Thanks one more time.

That's great. You are welcome. Thanks for providing feedback.

In case you are curious about the "~"& and &"" bits, you can safely take them away if the range of interest does not have any entries with special meaning chars around them like <, *, etc.
 
Upvote 0
Thanks Aladin and T.Valko.
I've always used Excel forums to search for answers where other people have asked the question, but today I just couldn't find an answer (as I was blinkered in to looking for a solution that involved modifying arrays), so I thought I'd give it a go myself. It's good to know there are people out there willing to lend a hand.


http://www.mrexcel.com/forum/member.php?u=117397
 
Upvote 0
Thanks Aladin and T.Valko.
I've always used Excel forums to search for answers where other people have asked the question, but today I just couldn't find an answer (as I was blinkered in to looking for a solution that involved modifying arrays), so I thought I'd give it a go myself. It's good to know there are people out there willing to lend a hand.
You're welcome. Thanks for the feedback! :cool:
 
Upvote 0

Forum statistics

Threads
1,224,542
Messages
6,179,424
Members
452,914
Latest member
echoix

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top