-
Another approach
It should handle cases if other than Col A or Col B is changed (just exits) and if you should paste or fill more that one row's worth of data.
As personal style, I like to define Const's to hold those kind of numbers, and to try to translate your business rules ( If ... and ... Then ...) into code. There didn't seem to be any performance issues, so I figured that it was OK
[VBA]
Option Explicit
Const cNET As Long = 1
Const cGROSS As Long = 2
Const cAE As Long = 3
Const cAW As Long = 4
Const cHC As Long = 5
Const cSH As Long = 6
Const cCT As Long = 7
Const cEXEC As Long = 8
Const c10K As Double = 10000#
Const c100K As Double = 100000#
Const c1M As Double = 1000000#
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rRow As Range, rFirst2Cols As Range
Set rFirst2Cols = Range(Me.Columns(1), Me.Columns(2))
If Intersect(Target, rFirst2Cols) Is Nothing Then Exit Sub
For Each rRow In Intersect(Target, rFirst2Cols).Rows
With rRow.EntireRow
.Cells(1, cAE).Resize(1, 6).Interior.ColorIndex = xlColorIndexAutomatic
If .Cells(1, cNET).Value <= c10K And .Cells(1, cGROSS).Value <= c100K Then
.Cells(1, cAE).Interior.ColorIndex = 8
ElseIf .Cells(1, cNET).Value <= c100K And .Cells(1, cGROSS).Value <= c1M Then
.Cells(1, cAE).Interior.ColorIndex = 8
.Cells(1, cAW).Interior.ColorIndex = 8
ElseIf .Cells(1, cNET).Value <= c1M And .Cells(1, cGROSS).Value <= 25 * c1M Then
.Cells(1, cAE).Interior.ColorIndex = 8
.Cells(1, cAW).Interior.ColorIndex = 8
ElseIf .Cells(1, cNET).Value <= 5 * c1M And .Cells(1, cGROSS).Value <= 100 * c1M Then
.Cells(1, cAW).Interior.ColorIndex = 8
.Cells(1, cHC).Interior.ColorIndex = 8
.Cells(1, cSH).Interior.ColorIndex = 8
ElseIf .Cells(1, cNET).Value <= 30 * c1M And .Cells(1, cGROSS).Value > 100 * c1M Then
.Cells(1, cAW).Interior.ColorIndex = 8
.Cells(1, cHC).Interior.ColorIndex = 8
.Cells(1, cSH).Interior.ColorIndex = 8
.Cells(1, cCT).Interior.ColorIndex = 8
ElseIf .Cells(1, cNET).Value > 30 * c1M Then
.Cells(1, cEXEC).Interior.ColorIndex = 8
End If
End With
Next
End Sub
[/VBA]
Paul
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules