Hi to all, KLAMI, a newbie to VBA here, asking for help.
I have a piece of code that currently colors an entire row dependent on the last number digit in a certain column. It then loops and does the same for the entire worksheet if required making rows of the various colors stipulated
Can someone please advise how I can change this to let it to continue to do the same but ignore non adjacent cells that may contain any one of 4 different colors in the same row, i.e. Black, Brown, grey and white?
I would also appreciate if someone could help me speed up the existing loop, if the problem above can not be resolved?
Here is the code that I use:
Sub ColourRow()
'
' Private Sub Worksheet_Change(ByVal Target As Range)
'
' CoulorIt Macro
'
' Dim rng As Range
Dim i As Long
Application.ScreenUpdating = False
Set rng = Range("B1:B5")
i = 2
Do
With rng
If Cells(i, 6).Value = "1" Then
Cells(i, 6).EntireRow.Interior.ColorIndex = 3
ElseIf Cells(i, 6).Value = "2" Then
Cells(i, 6).EntireRow.Interior.ColorIndex = 6
ElseIf Cells(i, 6).Value = "3" Then
Cells(i, 6).EntireRow.Interior.ColorIndex = 10
ElseIf Cells(i, 6).Value = "4" Then
Cells(i, 6).EntireRow.Interior.ColorIndex = 33
ElseIf Cells(i, 6).Value = "5" Then
Cells(i, 6).EntireRow.Interior.ColorIndex = 29
ElseIf Cells(i, 6).Value = "6" Then
Cells(i, 6).EntireRow.Interior.ColorIndex = 45
ElseIf Cells(i, 6).Value = "7" Then
Cells(i, 6).EntireRow.Interior.ColorIndex = 23
ElseIf Cells(i, 6).Value = "8" Then
Cells(i, 6).EntireRow.Interior.ColorIndex = 43
ElseIf Cells(i, 6).Value = "9" Then
Cells(i, 6).EntireRow.Interior.ColorIndex = 17
ElseIf Cells(i, 6).Value = "0" Then
Cells(i, 6).EntireRow.Interior.ColorIndex = 42
Else
Cells(i, 6).EntireRow.Interior.ColorIndex = 2
End If
End With
i = i + 1
Loop Until i = 100
Application.ScreenUpdating = True
End Sub
Thanks to any respondants
I have a piece of code that currently colors an entire row dependent on the last number digit in a certain column. It then loops and does the same for the entire worksheet if required making rows of the various colors stipulated
Can someone please advise how I can change this to let it to continue to do the same but ignore non adjacent cells that may contain any one of 4 different colors in the same row, i.e. Black, Brown, grey and white?
I would also appreciate if someone could help me speed up the existing loop, if the problem above can not be resolved?
Here is the code that I use:
Sub ColourRow()
'
' Private Sub Worksheet_Change(ByVal Target As Range)
'
' CoulorIt Macro
'
' Dim rng As Range
Dim i As Long
Application.ScreenUpdating = False
Set rng = Range("B1:B5")
i = 2
Do
With rng
If Cells(i, 6).Value = "1" Then
Cells(i, 6).EntireRow.Interior.ColorIndex = 3
ElseIf Cells(i, 6).Value = "2" Then
Cells(i, 6).EntireRow.Interior.ColorIndex = 6
ElseIf Cells(i, 6).Value = "3" Then
Cells(i, 6).EntireRow.Interior.ColorIndex = 10
ElseIf Cells(i, 6).Value = "4" Then
Cells(i, 6).EntireRow.Interior.ColorIndex = 33
ElseIf Cells(i, 6).Value = "5" Then
Cells(i, 6).EntireRow.Interior.ColorIndex = 29
ElseIf Cells(i, 6).Value = "6" Then
Cells(i, 6).EntireRow.Interior.ColorIndex = 45
ElseIf Cells(i, 6).Value = "7" Then
Cells(i, 6).EntireRow.Interior.ColorIndex = 23
ElseIf Cells(i, 6).Value = "8" Then
Cells(i, 6).EntireRow.Interior.ColorIndex = 43
ElseIf Cells(i, 6).Value = "9" Then
Cells(i, 6).EntireRow.Interior.ColorIndex = 17
ElseIf Cells(i, 6).Value = "0" Then
Cells(i, 6).EntireRow.Interior.ColorIndex = 42
Else
Cells(i, 6).EntireRow.Interior.ColorIndex = 2
End If
End With
i = i + 1
Loop Until i = 100
Application.ScreenUpdating = True
End Sub
Thanks to any respondants