Excel help - if then

Author
Discussion

craigjm

Original Poster:

17,951 posts

200 months

Friday 16th July 2021
quotequote all
I have a spreadsheet where the user is answering questions with 5 columns being the Likert scale from strongly agree to strongly disagree, I want to colour the cells in another column further along based on the answers to the questions so the cell goes green if they answer agree, amber if neither and red if disagree for example.

Im not sure I can do that with conditional formatting, will it require a macro?


otolith

56,091 posts

204 months

Friday 16th July 2021
quotequote all
Use a formula to convert their answer to a numeric value, and then use conditional formatting on the numeric value?

RizzoTheRat

25,162 posts

192 months

Friday 16th July 2021
quotequote all
Conditional formatting can do it. Select "New Rule" rather than predefined ones, and one of the options is to use a formula. Put in "=A1=1" (or =A1="Agree" if you're using text dropdowns) and then apply the formatting. You can have multiple conditional formats on a single cell so just have 5 to give the different colours (or 4 with the default being the 5th colour)

ETA: Just realised you mean they put something in one of 5 columns rather than a score. As above converting to a number works. If you're using True and False, it stores them as 1 or 0, so you could do a sum product with a list of 1 to 5 so if there's a true in column 3 it returns the number 3.

Edited by RizzoTheRat on Friday 16th July 10:25

Sporky

6,230 posts

64 months

Friday 16th July 2021
quotequote all
I would put a Group Box (from the Developer Tab, Insert, Form Controls) across all five responses, then five Option Buttons (again from the Developer Tab, Insert, Form Controls), with the option buttons all pointed at the cell in which you want to display the result.

I am going to assume that column A contains the question, then B-F are strongly disagree to strongly agree, then G has the colour code, like this (but line things up nicely):



Select G2, hit Conditional Formatting, New Rule, Use a formula, and then you'll need to do this three times:

First one - formula is "=G2<3", and hit the format button, set the fill to red
Second one - formula is "=G2=3", format button, fill to amber (or maybe yellow)
Third one - formula is "=g2>3", format button, fill to green

That should look like this:



You'll then just need to copy that all down your questions. I'm not sure Excel is the best tool for this, but as with many things, it may be the least bad tool you've got...

craigjm

Original Poster:

17,951 posts

200 months

Friday 16th July 2021
quotequote all
Sporky said:
I'm not sure Excel is the best tool for this, but as with many things, it may be the least bad tool you've got...
Thats exactly it. If it works for what we need it for after a proof of concept we may be able to shift it to something more suitable

Thanks for the explanation ill give it a go. Thanks everyone ill come back if I get stuck

craig_m67

949 posts

188 months

Friday 16th July 2021
quotequote all
craigjm said:
Sporky said:
I'm not sure Excel is the best tool for this, but as with many things, it may be the least bad tool you've got...
Thats exactly it. If it works for what we need it for after a proof of concept we may be able to shift it to something more suitable
Haha!
(35yrs in IT)

This will still be a supported legacy application (spreadsheet) when you retire.. look around you, one day lad, all this will be yours.. what the macros?!

randlemarcus

13,521 posts

231 months

Friday 16th July 2021
quotequote all
If you have 365, Forms is an excellent little thing...

RizzoTheRat

25,162 posts

192 months

Friday 16th July 2021
quotequote all
...unless you work for Public Health England hehe

craigjm

Original Poster:

17,951 posts

200 months

Tuesday 3rd August 2021
quotequote all
Sporky said:
I would put a Group Box (from the Developer Tab, Insert, Form Controls) across all five responses, then five Option Buttons (again from the Developer Tab, Insert, Form Controls), with the option buttons all pointed at the cell in which you want to display the result.

I am going to assume that column A contains the question, then B-F are strongly disagree to strongly agree, then G has the colour code, like this (but line things up nicely):



Select G2, hit Conditional Formatting, New Rule, Use a formula, and then you'll need to do this three times:

First one - formula is "=G2<3", and hit the format button, set the fill to red
Second one - formula is "=G2=3", format button, fill to amber (or maybe yellow)
Third one - formula is "=g2>3", format button, fill to green

That should look like this:



You'll then just need to copy that all down your questions. I'm not sure Excel is the best tool for this, but as with many things, it may be the least bad tool you've got...
Hey Sporky I have now sorted it using your solution, Thanks. Was just wondering if you know of a way of hiding the border around each question group? if you select it and then delete it the buttons dont function correctly as they are no longer in a group. I cant seem to colour the black line white or anything though like you would with normal formatting to hide it. Any ideas?


Sporky

6,230 posts

64 months

Tuesday 3rd August 2021
quotequote all
It's a form control, so I don't think you can (though happy to be corrected).

You can neaten it up a bit by removing the text (just tried one and it is called Group Box 1 by default), and aligning it with the grid lines - select the box, go to the Shape Format tab that then appears, click the Align dropdown towards the right hand end of the ribbon and choose "Snap to Grid" to make that easier.

craigjm

Original Poster:

17,951 posts

200 months

Tuesday 3rd August 2021
quotequote all
Thanks. I think I have found how, on the Mac version of Excel at least



Go into shape format then selection pane and then hide the item

Sporky

6,230 posts

64 months

Tuesday 3rd August 2021
quotequote all
Nifty! I did not know that.

craigjm

Original Poster:

17,951 posts

200 months

Tuesday 3rd August 2021
quotequote all
Thanks for your help thumbup

Sporky

6,230 posts

64 months

Tuesday 3rd August 2021
quotequote all
No probs. I've since thought of several other ways of doing it, but I think this is fairly elegant. For Excel... wink

craigjm

Original Poster:

17,951 posts

200 months

Tuesday 3rd August 2021
quotequote all
Its good enough for me to prove my concept and then we can get our coding team to make it into an app so it wont be kept in Excel for long just with this current client. Good to see that Excel can do it though