Auto Colour based on answer key

bushidowarrior

Board Regular
Joined
Jun 27, 2011
Messages
84
Office Version
  1. 2019
Platform
  1. Windows
Hello All,

I have this table below. As you can see in the KEY column, is has the correct answer. In this case it is C.

Is there a was to make "WHAT" the correct answer highlight in GREEN?

And for the next row it would be D (They're)




i2amBDn.png



I would really appreciate it.

I have over 100 questions, hence I would like to automate this process a little.

Thank you.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Hello All,

I have this table below. As you can see in the KEY column, is has the correct answer. In this case it is C.

Is there a was to make "WHAT" the correct answer highlight in GREEN?

And for the next row it would be D (They're)

.

I assumed KEY is in col A and A,B,C,D is actually at column B,C,D,E.
Try this:

Code:
[B][color=Royalblue]Sub[/color][/B] a1075737a()
[i][color=seagreen]'https://www.mrexcel.com/forum/excel-questions/1075737-auto-colour-based-answer-key.html[/color][/i]
[B][color=Royalblue]Dim[/color][/B] r [B][color=Royalblue]As[/color][/B] Range
[B][color=Royalblue]For[/color][/B] [B][color=Royalblue]Each[/color][/B] r [B][color=Royalblue]In[/color][/B] Range([color=brown]"A1"[/color], Cells(Rows.count, [color=brown]"A"[/color]).[B][color=Royalblue]End[/color][/B](xlUp))
Range(r & r.row).Offset([color=crimson]0[/color], [color=crimson]1[/color]).Interior.Color = vbGreen

[B][color=Royalblue]Next[/color][/B]
[B][color=Royalblue]End[/color][/B] [B][color=Royalblue]Sub[/color][/B]


Excel 2007 32 bit
[Table="width:, class:head"][tr=bgcolor:#008B8B][th] [/th][th]
A
[/th][th]
B
[/th][th]
C
[/th][th]
D
[/th][th]
E
[/th][/tr]
[tr=bgcolor:#FFFFFF][td=bgcolor:#008B8B]
1
[/td][td]key[/td][td]A[/td][td]B[/td][td]C[/td][td]D[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#008B8B]
2
[/td][td]C[/td][td][/td][td][/td][td=bgcolor:#00FF00][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#008B8B]
3
[/td][td]D[/td][td][/td][td][/td][td][/td][td=bgcolor:#00FF00][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#008B8B]
4
[/td][td]A[/td][td=bgcolor:#00FF00][/td][td][/td][td][/td][td][/td][/tr]
[/table]
[Table="width:, class:grid"][tr][td]Sheet: Sheet3[/td][/tr][/table]
 
Upvote 0
Hello, sorry. It is like this:

duwhNhU.png


I assumed KEY is in col A and A,B,C,D is actually at column B,C,D,E.
Try this:

Code:
[B][COLOR=Royalblue]Sub[/COLOR][/B] a1075737a()
[I][COLOR=seagreen]'https://www.mrexcel.com/forum/excel-questions/1075737-auto-colour-based-answer-key.html[/COLOR][/I]
[B][COLOR=Royalblue]Dim[/COLOR][/B] r [B][COLOR=Royalblue]As[/COLOR][/B] Range
[B][COLOR=Royalblue]For[/COLOR][/B] [B][COLOR=Royalblue]Each[/COLOR][/B] r [B][COLOR=Royalblue]In[/COLOR][/B] Range([COLOR=brown]"A1"[/COLOR], Cells(Rows.count, [COLOR=brown]"A"[/COLOR]).[B][COLOR=Royalblue]End[/COLOR][/B](xlUp))
Range(r & r.row).Offset([COLOR=crimson]0[/COLOR], [COLOR=crimson]1[/COLOR]).Interior.Color = vbGreen

[B][COLOR=Royalblue]Next[/COLOR][/B]
[B][COLOR=Royalblue]End[/COLOR][/B] [B][COLOR=Royalblue]Sub[/COLOR][/B]


Excel 2007 32 bit
[TABLE="class: head"]
<tbody>[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=008B8B]#008B8B[/URL] "]
[TH][/TH]
[TH]
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]A[/COLOR]​
[/TH]
[TH]
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]B[/COLOR]​
[/TH]
[TH]
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]C[/COLOR]​
[/TH]
[TH]
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]D[/COLOR]​
[/TH]
[TH]
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]E[/COLOR]​
[/TH]
[/TR]
[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] "]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=008B8B]#008B8B[/URL] "]
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]1[/COLOR]​
[/TD]
[TD]key[/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[/TR]
[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] "]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=008B8B]#008B8B[/URL] "]
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]2[/COLOR]​
[/TD]
[TD]C[/TD]
[TD][/TD]
[TD][/TD]
[TD="bgcolor: #00FF00"][/TD]
[TD][/TD]
[/TR]
[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] "]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=008B8B]#008B8B[/URL] "]
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]3[/COLOR]​
[/TD]
[TD]D[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="bgcolor: #00FF00"][/TD]
[/TR]
[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] "]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=008B8B]#008B8B[/URL] "]
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]4[/COLOR]​
[/TD]
[TD]A[/TD]
[TD="bgcolor: #00FF00"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="class: grid"]
<tbody>[TR]
[TD]Sheet: Sheet3[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Sub a1075737a()
'https://www.mrexcel.com/forum/excel-questions/1075737-auto-colour-based-answer-key.html
Dim r As Range
For Each r In Range("E1", Cells(Rows.count, "E").End(xlUp))
Range(r & r.row).Offset(0, 1).Interior.Color = vbGreen

Next
End Sub
 
Upvote 0
Sub a1075737a()
'https://www.mrexcel.com/forum/excel-questions/1075737-auto-colour-based-answer-key.html
Dim r As Range
For Each r In Range("E1", Cells(Rows.count, "E").End(xlUp))
Range(r & r.row).Offset(0, 1).Interior.Color = vbGreen

Next
End Sub

Yeah, I think you got it right. Does it work as expected?
 
Upvote 0
Ah, sorry, actually if the data start at row 2 then it should be E2.
Code:
Sub a1075737a()
'https://www.mrexcel.com/forum/excel-questions/1075737-auto-colour-based-answer-key.html
Dim r As Range
For Each r In Range("E2", Cells(Rows.count, "E").End(xlUp))
Range(r & r.row).Offset(0, 1).Interior.Color = vbGreen
Next
End Sub
 
Upvote 0
Again, sorry forget to change the Offset value, try this:
Code:
Sub a1075737a()
'https://www.mrexcel.com/forum/excel-questions/1075737-auto-colour-based-answer-key.html
Dim r As Range
For Each r In Range("E2", Cells(Rows.count, "E").End(xlUp))
Range(r & r.row).Offset(0, 5).Interior.Color = vbGreen
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,895
Messages
6,175,257
Members
452,625
Latest member
saadat28

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