Hi all,
find below a code for coloring cell based on the adjacent cell value. This code is running very slow, especially if the data in selection is more than 2000. Please help.
find below a code for coloring cell based on the adjacent cell value. This code is running very slow, especially if the data in selection is more than 2000. Please help.
Code:
Private Sub CommandButton2_Click()
Dim c As Range
firstVal = 0
cellColor = 0
With Selection
If Selection.Rows.Count > 100000 Then
MsgBox Prompt:="Please verify the data you have selected", Title:="Wrong selection!"
Exit Sub
Else
For Each c In Selection
If c.Interior.Color <> cellColor Then
firstVal = firstVal + 1
cellColor = c.Interior.Color
End If
Cells(c.Row, c.Column - 1).Value = firstVal
Next c
End If
End With
MsgBox "Process Completed Successfully."
Unload UserForm2
End Sub
Last edited by a moderator: