working with excel

G

Guest

I have a worksheet for a product which is supplied by different suppliers.
The worksheet compares the prices and retains the lowest price in a specified
cell. I want the result for the comparison to be displayed in a colour that
indicates the supplier colour code
 
B

Bob Phillips

If you have only a few suppliers, 4 or less, you could use conditional
formatting. If you have more, you would need event code, something like


Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "B2:H10"
Dim maxValue As Boolean

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
maxValue = .Value = Application.Max(.Value, Cells(.Row,
"B").Resize(1, 8))
If maxValue Then
Select Case .Column
Case 2: Cells(.Row, "A").Interior.ColorIndex = 3 'red
Case 3: Cells(.Row, "A").Interior.ColorIndex = 6 'yellow
Case 4: Cells(.Row, "A").Interior.ColorIndex = 5 'blue
Case 5: Cells(.Row, "A").Interior.ColorIndex = 10 'green
End Select
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--

HTH

RP
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top