ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   working with excel (https://www.excelbanter.com/excel-worksheet-functions/43626-working-excel.html)

Tinashe

working with excel
 
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

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)


"Tinashe" wrote in message
...
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





All times are GMT +1. The time now is 07:00 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com