Just learnt a power...
 

  You don't need to be an 'investor' to invest in Singletrack: 6 days left: 95% of target - Find out more

[Closed] Just learnt a powerful new Excel technique

93 Posts
38 Users
0 Reactions
369 Views
Posts: 36
Free Member
Topic starter
 

I know it's geeky, but these are the pleasures of a freelancer working on a Sunday evening. And I reckon there might be one or two Excel-ent people out there who might like this:

Criteria summing can be tricky. The base forumla rarely do exactly want you want them to. But this is a handy way of applying OR criteria to a SUM.

Say you have a range of codes and you want to sum corrsponding values in a neighbouring range where the codes have particular similarity.

For example, in a range of codes:

DG345345
JUH234234234
SDFDSL12391
SDFSDF1243114
[b]AB[/b]123
JJ23452345
[b]AB[/b]CVS
AFF908
[b]AB[/b]4
LK09780987

You want to sum corresponding values in a neighbouring column for any code that STARTS "[b]AB[/b]". (lets put "[b]AB[/b]" in cell F1)

if you use:

=SUMPRODUCT(--(LEFT(A1:A10,LEN(F1))=F1),B1:B10)

what it does is turn A1:A10 into an array of values with the same length as the value in F1 (i.e. two digits) and then compares those two digit array values ("DG", "JU", "SD" etc), with the contents of F1 ("AB") to give an array of TRUEs and FALSEs. The "--" then converts the Trues and Falses into an array of 1s and 0s with which to multiply your Value array with to get the SUMPRODUCT

Bloody fantastic!
I did a little sexy frot. 😳

Imagine what other functions you could do this with (LEFT, RIGHT, MATCH FIND etc!)

Sorry.
But Ive earned my bottle of wine now.


 
Posted : 29/04/2012 6:52 pm
Posts: 77347
Free Member
 

That's really rather clever; I've not seen the "--" bit before. Well done.


 
Posted : 29/04/2012 6:54 pm
Posts: 0
Free Member
 

Good work Stoner... I may well pinch bits of that. Ta.


 
Posted : 29/04/2012 6:56 pm
Posts: 1318
Full Member
 

Very neat - but for the original problem, wouldn't SUMIF(...) do what you wanted?


 
Posted : 29/04/2012 6:56 pm
Posts: 36
Free Member
Topic starter
 

I cant take much credit for it. I had to reverse something posted here
http://www.excelbanter.com/showthread.php?p=384506#post384506

and found I could use the principal in other ways.


 
Posted : 29/04/2012 6:57 pm
Posts: 19434
Free Member
 

Wow ... :mrgreen:


 
Posted : 29/04/2012 6:58 pm
Posts: 36
Free Member
Topic starter
 

SUMIF wont handle "LEFT" in the Range argument.


 
Posted : 29/04/2012 6:58 pm
Posts: 5936
Free Member
 

bit of an excel novice, but wouldn't vlookup do the same thing?


 
Posted : 29/04/2012 7:00 pm
Posts: 0
Free Member
 

Oh, the nasty world of VBA.

Nice bit of stuff there. There was a VBA role going in Andover @ £650 / day recently...

Bit niche for me, though!


 
Posted : 29/04/2012 7:02 pm
Posts: 36
Free Member
Topic starter
 

BTW - Im using to group cashflows for 300 rows of data on a dozen sheets that have nicely structured id codes that embed about 4 classifications in the code (i.e. building number, phase number, building floor and sub-plot for example).

This formula lets me make a summary page driven by a handful of drop down boxes that specify the classifications I want to filter by and then aggregates by them or even a combination of filters.


 
Posted : 29/04/2012 7:03 pm
Posts: 36
Free Member
Topic starter
 

I hate VBA. I really only ever work in functions (which is what that ^ up there is) unless I need to run a macro.


 
Posted : 29/04/2012 7:03 pm
Posts: 13741
Full Member
 

<backs out of thread>


 
Posted : 29/04/2012 7:05 pm
Posts: 19434
Free Member
 

I used to spend hours trying to figure out how to create the right formula only for my mate to create one within 15 mins ... 😡


 
Posted : 29/04/2012 7:05 pm
Posts: 1318
Full Member
 

SUMIF wont handle "LEFT" in the Range argument.

Hadn't realised that - nice one and I'll tuck that away for when it might be useful!

You could create another column with the LEFT bit in it and still use SUMIF - but it's a nice trick to do it in the one cell.


 
Posted : 29/04/2012 7:05 pm
Posts: 36
Free Member
Topic starter
 

but wouldn't vlookup do the same thing

short answer, no.


 
Posted : 29/04/2012 7:06 pm
Posts: 36
Free Member
Topic starter
 

You could create another column with the LEFT bit in it and still use SUMIF

Unfortunately I dont "Own" the primary model. Im building a "translator" that overlays. I cant disturb the model itself by including columns, and whilst I could add loads of sheets to do the same thing (and that was going to be my back up) I really wanted to find an efficient single cell solution. And did.

I feel all fuzzy now.


 
Posted : 29/04/2012 7:08 pm
Posts: 0
Free Member
 

Is confused 😳

The most powerfull excel tool i know is that if you click the bottom right corner of a box and dragg it down it'll copy the data from that cell down. Winner winner chicken dinner 😀


 
Posted : 29/04/2012 7:08 pm
Posts: 5936
Free Member
 

but wouldn't vlookup do the same thing
short answer, no.

That'll do me 😀


 
Posted : 29/04/2012 7:09 pm
Posts: 0
Free Member
 

=vlookup("Stwer Pisses on Stoner's chips",DataRangeAllposts,1,0)
=#N/A


 
Posted : 29/04/2012 7:12 pm
Posts: 36
Free Member
Topic starter
 

=ISERROR(Stoner is a God)
=FALSE


 
Posted : 29/04/2012 7:16 pm
Posts: 4
Free Member
 

*Leaves thread once he realises it wasn't about colour coding a contact list*


 
Posted : 29/04/2012 7:23 pm
Posts: 79
Free Member
 

I have a few 'Stoner nuggets' stashed away in notepad at work. This is another beauty to add to the list. 😀


 
Posted : 29/04/2012 7:25 pm
Posts: 0
Free Member
 

Very neat bit of coding.

VBA's great until you have to check it. Much easier to work out what some whizz kid has done wrong if they stick to conventional functions


 
Posted : 29/04/2012 7:25 pm
Posts: 36
Free Member
Topic starter
 

Stoner nuggets

😯

can I have them back? 😉


 
Posted : 29/04/2012 7:28 pm
Posts: 11
Free Member
 

Now that's a good day's work, especially after just winning the Spanish motogp!


 
Posted : 29/04/2012 7:46 pm
Posts: 11402
Free Member
 

should'nt it be

=SUMPRODUCT(--(LEFT(A1:A10,LEN($F$1))=$F$1),B1:B10)

?


 
Posted : 29/04/2012 7:53 pm
Posts: 36
Free Member
Topic starter
 

well duh. 😉
Just indicative code without cluttering it with locks.


 
Posted : 29/04/2012 7:57 pm
Posts: 11402
Free Member
 

neat slick solutions are always gratifying, but it's hard to get excited by excel 😉


 
Posted : 29/04/2012 8:09 pm
Posts: 0
Free Member
 

erm.............what tyres would I need for this.....? 😳


 
Posted : 29/04/2012 8:10 pm
Posts: 0
Full Member
 

Nice. Will have to remember that one and have a play when I get back to the office.

[img] [/img]


 
Posted : 29/04/2012 8:15 pm
Posts: 36
Free Member
Topic starter
 

but it's hard to get excited by excel

Mine certainly gets hard when Im excited by Excel 😉


 
Posted : 29/04/2012 8:16 pm
Posts: 28
Free Member
 

* reports thread for being the sort of shameless filth that no one should stumble into on a Sunday evening *


 
Posted : 29/04/2012 8:16 pm
Posts: 4097
Free Member
 

That's a great piece of work.

I'll be using that. And checking your other threads.


 
Posted : 29/04/2012 8:19 pm
Posts: 41395
Free Member
 

*notes those posting for when he is in power*


 
Posted : 29/04/2012 8:20 pm
Posts: 0
Free Member
 

Klunk - Member
neat slick solutions are always gratifying, but it's hard to get excited by excel

Agreed

{Pretends he didn't dance round the kitchen last week after finally getting a graph to display properly}


 
Posted : 29/04/2012 8:22 pm
Posts: 268
Free Member
 

Stoner, a fellow excexual.

I have a lot of...deep...stuff.


 
Posted : 29/04/2012 8:24 pm
Posts: 0
Free Member
 

[img] [/img]


 
Posted : 29/04/2012 8:35 pm
Posts: 0
Free Member
 

[img] [/img]

Hmmmm. I'm picking up extremely high levels of geek


 
Posted : 29/04/2012 8:37 pm
Posts: 0
Full Member
 

cynic-al - Member
*notes those posting for when he is in power*

*adds cynic-al to the big shared table of individuals that The Spreadsheet Illuminati will keep from "power"*


 
Posted : 29/04/2012 8:39 pm
Posts: 36
Free Member
Topic starter
 

geek is sexy
[img] [/img]


 
Posted : 29/04/2012 8:40 pm
Posts: 36
Free Member
Topic starter
 

*notes those posting for when he is in power*

Cynical realises that you cant hope to run the world without the help of Excel geeks.


 
Posted : 29/04/2012 8:41 pm
Posts: 268
Free Member
 

7 of 9. We have...met, vividly, in my teens.....i hope it wasn't in my twenties.


 
Posted : 29/04/2012 8:47 pm
Posts: 36
Free Member
Topic starter
 

she and I have "assimilated" on a number of occasions...


 
Posted : 29/04/2012 8:50 pm
Posts: 13594
Free Member
 

I only ever use VBA code now and just do everything in that as it's just as quick once you're fluent and it has better maintainability and documentability than formulas in cells.


 
Posted : 29/04/2012 9:01 pm
Posts: 11402
Free Member
 

shame this [url= http://www.ioccc.org/ ]place [/url]doesn't have a forum, you'd fit right in Stoner.


 
Posted : 29/04/2012 9:31 pm
Posts: 4954
Free Member
 

I think you would befit from learning python or something, impressive little trick using excel stoner but it just screams wrong tool for the job!


 
Posted : 29/04/2012 9:36 pm
Posts: 36
Free Member
Topic starter
 

d'ja miss the bit when I said it was a module for viewing an existing Excel model with?

But full marks for the traditional STW approach to a thread...want a new steel hardtail? I recommend a Santa Cruz Blur!

😉


 
Posted : 29/04/2012 9:44 pm
Posts: 0
Free Member
 

Clever. Will have to see if I can use that. Chances are, not. But I still like it.


 
Posted : 29/04/2012 9:52 pm
Posts: 0
Free Member
 

Powerful might be overstating it, though.


 
Posted : 29/04/2012 9:54 pm
Posts: 1642
Free Member
 

Wot footflaps said.


 
Posted : 29/04/2012 9:57 pm
Posts: 25815
Full Member
 

OK clever cloggses, excel me this:

how do I make excel look at text in 2 adjacent cells and then if both fit a defined pattern, change the contents of one of those cells. I'm going to macro the bugger after that and save myself about 5 hours a month

|manually titting about is OK|stoner's excel macro tips are 20 x better|

becomes

|manually titting about is OK|20 x less menial crap|

but

|working it out for yourself will never happen|stoner's excel macro tips are 20 x better|

stays as it is


 
Posted : 29/04/2012 10:52 pm
Posts: 1781
Free Member
 

Sumproduct function is truly the wonder of Excel, back in the good old days when people wanted to pay me with twiddling about with it I used to use it all the time.

This is the place to learn it: http://www.xldynamic.com/source/xld.SUMPRODUCT.html Bob is pretty much recognised as the world expert when it comes to Sumproduct.

I hate VBA. I really only ever work in functions (which is what that ^ up there is) unless I need to run a macro.

UDFs are so handy sometimes (& powerful!); VBA can make things so much tidier.


 
Posted : 29/04/2012 11:03 pm
Posts: 36
Free Member
Topic starter
 

cheers for the link Rob, will go and explore.

As for UDF's my problem is my models have to be used (and to a certain extent be understood) by the client and UDF's or reams of VBA behind a sheet just isnt going to cut it. The objective has always been to make the models slim and efficient using all the standard, documented, functions available.

Scaredypants,

how do I make excel look at text in 2 adjacent cells and then if both fit a defined pattern

define your pattern and I can have a look at it for you.


 
Posted : 30/04/2012 5:59 am
Posts: 0
Free Member
 

what rubbish, try this:

1. Open Excel 2000.
2. Go to File, Save as Web Page.
3, Then click Publish.
4. Check the checkbox that says "Add Interactively With".
5. Click Publish.
6. Close Excel.
7. Open IE.
8. Click File, Open, Browse.
9. Go to where you saved it and click open.
10.Now you should be looking at a spreadsheet.
11. Go to all the way to row 2000.
12. Click column A and drag all the way to column ZZ.
13. Hit Tab and it should take you back to A.
14. Hold Tab all the way to column WC. (Press shift Tab in case you move back).
15. When you get there make sure WC is a white box and all the others are blue or green..
16. Hold Ctrl+alt+shift and left click on the "four puzzle pieces" thing (The
MS Excel Logo) on the upper left hand corner..


 
Posted : 30/04/2012 6:17 am
Posts: 10315
Full Member
 

This is the place to learn it: http://www.xldynamic.com/source/xld.SUMPRODUCT.html

Nice link Rob - that explains it all very well


 
Posted : 30/04/2012 6:41 am
Posts: 25815
Full Member
 

define your pattern and I can have a look at it for you
Cheers, but no pattern, this is a large database of descriptive terms that should use the 2nd column to categorise them but this has been done inconsistently without any logic at all - consequently there are multiple instances of "cross-categorisation" that I currently have to clean up manually line by line
(I'm imagining a glorified search & replace function but can't see how I could do it)
🙁
yeah, 1stworldwhining - I know


 
Posted : 30/04/2012 6:49 am
Posts: 36
Free Member
Topic starter
 

I'm betting there was a secretary involved somewhere along the line with that, eh scaredy 😉


 
Posted : 30/04/2012 7:01 am
Posts: 25815
Full Member
 

nope, a supposedly qualified person 🙄 (we're all just muddling through, [u]none[/u] of us does IT and what I'm trying to do wasn't envisaged when they started with this crap)


 
Posted : 30/04/2012 7:08 am
 IHN
Posts: 19694
Full Member
 

Stoner, I've said it before and I'll say it again, I can see how you get all the girls.

[img] [/img]


 
Posted : 30/04/2012 7:54 am
Posts: 1781
Free Member
 

slim and efficient using all the standard, documented, functions available.

Non sequitur :mrgreen:

If you're using Sumproduct you've got a client who can't follow what you're doing anyway 🙂 Bits of code can make it all so much smoother and, even, easier for the client to follow & even edit, rather than formulae that rely on helper cells etc. Not least because you can add notes to the code.

There's sooooo much you can do in VBA to make your models slick that you can't use the front end for - go on, do it! You know you want to!


 
Posted : 30/04/2012 8:39 am
Posts: 36
Free Member
Topic starter
 

for the client to follow & [u]even edit[/u],

haha! Comedian! 😆

Anyway, this old dog isnt going to be learning any VBA tricks any time soon.

That link is great Rob, dont know why it never turned up on my google searches in the past. bookmarked now.


 
Posted : 30/04/2012 9:44 am
Posts: 79
Free Member
 

This is the place to learn it: http://www.xldynamic.com/source/xld.SUMPRODUCT.html

Well timed link from Rob. Just had a quick glance and it definitely looks interesting. Bookmarked.
Stoner: keep 'em coming 🙂


 
Posted : 30/04/2012 10:09 am
Posts: 1781
Free Member
 

haha! Comedian!

I'm seriously! Some people even appreciate that you view them as potentially competant and start to delve into the mysteries themselves.

Give a man a fish etc.

Anyhoo... try putting "Ozgrid" in your search text - most of the answers are in there somewhere.


 
Posted : 30/04/2012 10:24 am
Posts: 36
Free Member
Topic starter
 

Give a man a fish etc.

And give him a rod and he'll #REF for the rest of his life 🙂

Ive found some stuff off Ozgrid, but sometimes it's tricky trying to pick through some of the crappier user posts that clutter up otherwise useful threads.


 
Posted : 30/04/2012 10:36 am
Posts: 79
Free Member
 

tricky trying to pick through some of the crappier user posts that clutter up otherwise useful threads

Just like STW then 😉


 
Posted : 30/04/2012 11:15 am
 PJay
Posts: 4818
Free Member
 

Hmmm, sometimes not knowing too much about spreadsheets could be a good thing as it saves you getting to tied up with complexities (I haven't learn sumproduct yet).

[b]=SUMIFS(B1:B10,A1:A10,"AB*")[/b] works for me (Excel even highlights the parts of the criteria range matched by the wildcard) 😮


 
Posted : 30/04/2012 1:05 pm
Posts: 1781
Free Member
 

^ New in 07 (I'm still stuck in 05 🙂 ) Sumifs does the job nicely, but isn't as flexible as Sumproduct (which can be used for really unexpected things).

The database functions can also be used for such type things, but I never bothered to learn them.


 
Posted : 30/04/2012 1:12 pm
Posts: 50252
Free Member
 

Wow, do you guys know how to party or WHAT!

😉


 
Posted : 30/04/2012 1:19 pm
Posts: 1781
Free Member
 

^ :mrgreen:

It's either this or arguing with TJ.

Or getting on with what I'm sposed to be doing...


 
Posted : 30/04/2012 1:26 pm
Posts: 36
Free Member
Topic starter
 

SUMIFS is a handy addition to 2010 and fills some of the functional gaps in SUMIF. But while it works for search AB* etc, I was using it as an illustration for using [u]any[/u] logical test and in any array as a SUM criteria, which SUMIFS cant handle.

Wow, do you guys know how to party or WHAT!

Mine's a diet coke and a taxi home by 9pm please 😉


 
Posted : 30/04/2012 1:37 pm
Posts: 1781
Free Member
 

SUMIFS is a handy addition to 2010

*Ahem*

New in 07

Rob needs to leave the glowing screen alone for a while :mrgreen:


 
Posted : 30/04/2012 1:48 pm
Posts: 0
Full Member
 

All help with knowledge share...

These guys we use quite regularly and encouraged.

[url= http://www.ozgrid.com/VBA/ ]VBA/Excel'ist help [/url]
[url= http://www.mrexcel.com/archive/Formulas/index.html ]Excel'ist help guru[/url]


 
Posted : 30/04/2012 1:48 pm
Posts: 36
Free Member
Topic starter
 

New in 07

Hey, Ive only just moved up from 2003! Im still suffering culture shock!
🙂


 
Posted : 30/04/2012 2:50 pm
Posts: 79
Free Member
 

3 pages on Excel!!! it's not often posts reach double figures.


 
Posted : 30/04/2012 2:57 pm
Posts: 11402
Free Member
 

as this is a flaunt your geek week, heres one of [url= http://forums.cgsociety.org/forumdisplay.php?f=98 ]mine[/url]


 
Posted : 30/04/2012 3:05 pm
Posts: 36
Free Member
Topic starter
 

is the whole forum yours or were you trying to link to a specific post?


 
Posted : 30/04/2012 3:43 pm
Posts: 0
Free Member
 

is the whole forum yours or were you trying to link to a specific post?

I think he was demonstrating his ability to include links in his text within a forum


 
Posted : 30/04/2012 3:51 pm
Posts: 0
Free Member
 

Cheers Stoner, just saved me some time and no doubt more in the future with that formula.


 
Posted : 01/05/2012 8:54 am
Posts: 36
Free Member
Topic starter
 

good to hear. Didnt realise there might be a backlog of demand for the "Double Unary" (--) ! 😉

Ive just sat down to use the formula in earnest now. Lets hope it holds up ....


 
Posted : 01/05/2012 9:19 am
Posts: 2
Free Member
 

I am loving the XmlImport method in VBA at the moment enabling me to pull in loads of data from the web manipulate it and re publish it.

VBA is where its at there is only so much you can do with functions.


 
Posted : 01/05/2012 9:32 am
Page 1 / 2

6 DAYS LEFT
We are currently at 95% of our target!