VB for macro needed urgent

sparq

New Member
Joined
Apr 3, 2011
Messages
3
here's my problem i need a code so that the text is on the adjacent cell not on the same cell, if the cell is color red the message next to it is "out of parameter", and another color is green, and the message next to it should be "ok" the messages should be on the next column(F2:F50).



Sub ParameterCheck()
Set colorcheck = Range("E2:E50")
For Each Cell In colorcheck

If Cell.Interior.ColorIndex = 3 Then
Cell.Value = "Out of Parameter"
If Cell.Interior.ColorIndex = 10 Then
Cell.Value = "Ok"

End If
End Sub


as soon as i run the macro, it displays the message on the cell itself. Help pls. Thanks in advance.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Welcome to the board!

Try

Code:
Sub ParameterCheck()
Set colorcheck = Range("B2:B50")
For Each Cell In colorcheck
If Cell.Interior.ColorIndex = 3 Then
Cell.Offset(, 1) = "Out of Parameter"
If Cell.Interior.ColorIndex = 10 Then
Cell.Offset(, 1) = "Ok"
End If
End If
Next
End Sub

Can also be done without VB if preferred.
 
Upvote 0
how would be the code be if the its only used in a specific cell?
for example B2 would be the color then the color on C2?
 
Upvote 0
Something like

Rich (BB code):
Sub ParameterCheck()
If Range("B2").Interior.ColorIndex = 3 Then Range("C2") = "Out of Parameter"
If Range("B2").Interior.ColorIndex = 10 Then Range("C2") = "Ok"
End Sub

Also just noticed a problem with the previous code, there was an End If in the wrong place, corrected below.

Rich (BB code):
Sub ParameterCheck()
Set colorcheck = Range("B2:B50")
For Each Cell In colorcheck
If Cell.Interior.ColorIndex = 3 Then
Cell.Offset(, 1) = "Out of Parameter"
End If
If Cell.Interior.ColorIndex = 10 Then
Cell.Offset(, 1) = "Ok"
End If
Next
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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