VB Program - To Change the Color of the cell based on the values.
Program:
The below code change the color of the cell based on specific values as defined in the code.
Sub Color()
For i = 1 To 100
Cell1 = "A" + CStr(i)
val1 = Range(Cell1).Value
If val1 = "1" Then
Range(Cell1).Select
Selection.Interior.ColorIndex = 43
ElseIf val1 = "no progress" Then
Range(Cell1).Select
Selection.Interior.ColorIndex = 15
ElseIf val1 = "0" Then
Range(Cell1).Select
Selection.Interior.ColorIndex = 3
Else
Range(Cell1).Select
Selection.Interior.ColorIndex = 35
End If
Next
End Sub
Note: Copy the code and run in Microsoft Visual Basic Editor.(Microsoft Excel)
Program:
The below code change the color of the cell based on specific values as defined in the code.
Sub Color()
For i = 1 To 100
Cell1 = "A" + CStr(i)
val1 = Range(Cell1).Value
If val1 = "1" Then
Range(Cell1).Select
Selection.Interior.ColorIndex = 43
ElseIf val1 = "no progress" Then
Range(Cell1).Select
Selection.Interior.ColorIndex = 15
ElseIf val1 = "0" Then
Range(Cell1).Select
Selection.Interior.ColorIndex = 3
Else
Range(Cell1).Select
Selection.Interior.ColorIndex = 35
End If
Next
End Sub
Note: Copy the code and run in Microsoft Visual Basic Editor.(Microsoft Excel)
No comments:
Post a Comment