Is this a problem which can be solved?

User avatar
John Gray
PlatinumLounger
Posts: 5408
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Is this a problem which can be solved?

Post by John Gray »

I posted the following problem in the Excel section, and now wonder whether it can be solved in Word without the use of VBA...

Suppose I have a two-column table like the following, where all the text is in the first column and the numbers are in the second column:

Cat Tabby 5
Dog Jack Russell 8
Cat Burmese 9
Ferret Noble British 11
Dog Miniature Schnauzer 22
Cat Siamese 6
<a blank row>
Dog Miniature Poodle 7
Crocodile Sharp-toothed 43
Badger Black-and-white 321

I want to calculate the total number of cats
and the total number of dogs
by testing the first three characters of A1, A2, A3...
and ignoring all blank, and non-cat/non-dog rows.

Somehow I don't think this can be done without VBA, but it would be nice for an expert to confirm this!

Thanks!
John Gray

"(or one of the team)" - how your appointment letter indicates you won't be seeing the Consultant...

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: Is this a problem which can be solved?

Post by Rudi »

Although Word has various calculative fields (incl. IF), it does not have LEFT() or SUMIF or Array capability.
Also, AFAIK, Word can ONLY calculate with numbers.
So, even if you did extract Cat and Dog into (for argument sake), the C column, you cannot use =IF(C1="Cat",1,0) as one cannot use text in calculations.
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

User avatar
HansV
Administrator
Posts: 78494
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Is this a problem which can be solved?

Post by HansV »

Let's see if macropod reads this thread - if it is possible at all, he will know how to do it.
Best wishes,
Hans

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: Is this a problem which can be solved?

Post by Rudi »

Here is a bit of reading (TX to Macropod) attached. (From this post in Windows Secrets)
It might be possible by using bookmarks in the conditional expression....
Word Field Maths.zip
You do not have the required permissions to view the files attached to this post.
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15630
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Is this a problem which can be solved?

Post by ChrisGreaves »

John Gray wrote:Thanks!
(attached)

You're welcome!
You do not have the required permissions to view the files attached to this post.
There's nothing heavier than an empty water bottle

User avatar
HansV
Administrator
Posts: 78494
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Is this a problem which can be solved?

Post by HansV »

:hairout: :hairout: :hairout:
Best wishes,
Hans

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: Is this a problem which can be solved?

Post by Rudi »

Very nice Chris...
John may find this very handy indeed. :tongue:
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15630
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Is this a problem which can be solved?

Post by ChrisGreaves »

HansV wrote::hairout: :hairout: :hairout:
Well, at least I landed it in the correct conference!
Since my Turing machine has gotten as far as comparing two character strings of any length by converting each character to ASCII as a string of binary characters, perhaps John would like to avail himself ...
There's nothing heavier than an empty water bottle