Excel help - letter...
 

Subscribe now and choose from over 30 free gifts worth up to £49 - Plus get £25 to spend in our shop

[Closed] Excel help - letters to numbers...

11 Posts
6 Users
0 Reactions
80 Views
 gee
Posts: 0
Free Member
Topic starter
 

I wonder if someone can help... I have a row of grades a-d, and some blank cells that I want it to ignore, which I need to be able to report an average of as a number where a=1, b=2, c=3 and d=4. It's important that it ignores blanks rather than assumes blank=0 as that really affects the average. i.e. if I had a,a,a,c then it would report 1.50.

I am currently doing this by running a mirror sheet which uses vlookup to convert each letter to a number, and then =average to work out what I need. There must be a way of doing this in one cell without the mirror sheet, but I can't work out what that is. Anyone....?


 
Posted : 19/02/2018 2:44 pm
Posts: 77687
Free Member
 

I don't know a vast amount of Excel so I don't know if this will help, but you can do it computationally.

You can use CODE to convert it to ASCII, which is 65 for A, 66 for B and so forth.  Subtract 64 from this and you've got A=1 etc.  (Lower case starts with a=97).


 
Posted : 19/02/2018 3:01 pm
 tiim
Posts: 0
Free Member
 

Nested if statement?

=IF(A1="a",4,IF(A1="b",3,IF(A1="c",2,IF(A1="d",1,""))))


 
Posted : 19/02/2018 3:08 pm
Posts: 1142
Full Member
 

Nested if statement?

I tend to use SWITCH instead of nested if -

=SWITCH(A1,"a",1,"b",2,"c",3,"d",4,"")

RM.


 
Posted : 19/02/2018 3:14 pm
Posts: 8699
Full Member
 

Easier way to convert a letter to a number

=COLUMN(INDIRECT(A1&1))

but I haven't thought of an easy one formula way to do what the OP wants without a rather long formula


 
Posted : 19/02/2018 3:19 pm
 tiim
Posts: 0
Free Member
 

I tend to use SWITCH instead of nested if –

=SWITCH(A1,”a”,1,”b”,2,”c”,3,”d”,4,””)

Nice - Elegant.


 
Posted : 19/02/2018 3:47 pm
Posts: 1781
Free Member
 

Here you go, OP.

=SUMPRODUCT(({"a";"b";"c";"d"}=A1:J1)*{1;2;3;4})/COUNTA(A1:J1)

Change "A1:J1" to whatever it needs to be. If you get stuck, shout.


 
Posted : 19/02/2018 3:54 pm
Posts: 8699
Full Member
 

Nice solution Rob Hilton


 
Posted : 19/02/2018 5:30 pm
 gee
Posts: 0
Free Member
Topic starter
 

Rob - thank you very much for your time, that doesn't seem to work - I get a "did you mean to enter a formula?" error.

Any ideas? I copy/pasted it in and changed both cell ranges to the ones I need. Tried entering as array formula and normal formula - no difference. I thought with an array formula that you didn't enter the curly brackets and just press ctrl+shift+enter?


 
Posted : 19/02/2018 7:21 pm
Posts: 8699
Full Member
 

Rob's formula works a treat, I gave it a try but.......you may need to replace the copy and pasted speech marks with ones you type in yourself


 
Posted : 19/02/2018 7:30 pm
Posts: 1781
Free Member
 

RB is probly right.

Sumproduct() is an array function, so no need to ctrl+shift+enter. You can use arrays as arguments in other "regular" functions too. Very powerful things can be done :).


 
Posted : 19/02/2018 7:42 pm
 gee
Posts: 0
Free Member
Topic starter
 

Amazing - thank you. Replacing the quotation marks fixed it.


 
Posted : 20/02/2018 8:12 pm