0

I am trying to write an ifelse statement to show that if the text in column B is equal to "Green" then Column C should say "Go". If Column B is equal to "Yellow" then Column C should say "Yield" and if column B is equal to "Red" then Column C should say "Stop"

I was using the below code. The code says it completes but nothing gets populated.

 If Range("B7:B50").Text = "Green" Then
   Range("C7:C50").Text = "Go"
   ElseIf Range("B7:B50").Text = "Yellow" Then
   Range("C7:C50").Text = "Yield"
   ElseIf Range("B7:B50").Text = "Red" Then
   Range("C7:C50").Text = "Stop"    
 End If

Can someone take a look and help me out?

Scott Craner
  • 148,073
  • 10
  • 49
  • 81
  • 2
    You will need to loop. You cannot test equate a range/array to a single text string. – Scott Craner Feb 27 '23 at 16:25
  • 1
    I'm surprised you don't get a generic run-time error with this code. – JNevill Feb 27 '23 at 16:27
  • 1
    ^^^^^ My guess is you have an improper use of `On Error Resume Next` somewhere before this block. That needs to be removed and the code should be written to deal with the errors. – Scott Craner Feb 27 '23 at 16:30
  • @ScottCraner @JNevill: You can use the `Text`-property on a Range that contains more than one cell, however, it will return `Null` in that case. – FunThomas Feb 28 '23 at 08:17
  • @User275: As Scott Craner wrote, you will need to loop as you can check only one cell at a time. You should use the `Value`-property of the cells, not the `Text`-property. – FunThomas Feb 28 '23 at 08:18

0 Answers0