ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to use VB for multiple conditions (https://www.excelbanter.com/excel-programming/422758-re-how-use-vbulletin-multiple-conditions.html)

Gary''s Student

How to use VB for multiple conditions
 
This is coded for data entry on column A. Put this event macro in the
worksheet code area:

Private Sub Worksheet_Change(ByVal Target As Range)
codes = ("V,F,A,OC,CO,O1,O2,O3,O4,O5,O6,O7,O8")
Acodes = Split(codes, ",")
Set t = Target
Set a = Range("A:A")
If Intersect(t, a) Is Nothing Then Exit Sub
v = t.Value
For i = LBound(Acodes) To UBound(Acodes)
If v = Acodes(i) Then
t.Interior.ColorIndex = i
End If
Next
End Sub
--
Gary''s Student - gsnu200828


"OsmoseTom" wrote:

I need some help. I need to change the color of a cell based on values from
a list. The list options are V, F, A, OC, CO, O1, O2, O3, O4, O5, O6, O7, &
O8. Each option would have to be a different color. Can this be done using
VB code for the current worksheet? If so how? Thanks...



All times are GMT +1. The time now is 06:02 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com