Mark in red color for unidentifided Numbers

anand3dinesh

Board Regular
Joined
Dec 19, 2019
Messages
78
Office Version
  1. 2016
Platform
  1. Windows
Hi All,

please check my code below, this code finds number in Main sheet and makes color change in respective sheets based on its usage
lets say if the usage app in main sheet then code makes perticular row to green colour in other sheets
if the usage is Ex then it marks that row in yellow color.
my other condition is if the number not available in main sheet then it shoul mark the row in Red color.

any help please?
i don't think i explained it pretty well but i hope you understand what i mean once you go through my code below.

---------------------------------------------------------------------------------------------------------------------------------------------------------

Sub ColCodeVINs()

Dim LVE As Worksheet

Set LVE = Sheets("Live Vehicles Extract")
Dim ws As Worksheet
Dim Lrow As Long
Dim i As Long
Dim VIN As Long
Dim Usage As String
Dim Utilisation As Worksheet
Set Utilisation = Sheets("Summary (Drill-Down) Mod")


Application.ScreenUpdating = False

For Each ws In Sheets(Array("EA", "EE", "EF", "EG", "ET", "EP", "EK", "MSP"))

ws.Activate
Lrow = Range("A10000").End(xlUp).Row
For i = 2 To Lrow

VIN = Range("A" & i).Value
Usage = Sheets("VUP Utilisation").Cells.Find(VIN).Offset(0, 3).Value

On Error Resume Next
ws.Range("G" & i).Value = Application.WorksheetFunction.VLookup(VIN, Utilisation.Range("E:F"), 2, 0)
ws.Range("G" & i).NumberFormat = "0.00%"
On Error GoTo 0

If Usage = "App" Or Usage = "Donor" Or Usage = "Bond" Then
ws.Range("A" & i & ":" & "G" & i).Interior.Color = 5296274

ElseIf Usage = "Ex" Then
ws.Range("A" & i & ":" & "G" & i).Interior.Color = 65535

Else
ws.Range("A" & i & ":" & "G" & i).Interior.Color = 255
ws.Range("A" & i & ":" & "G" & i).Font.Color = RGB(255, 255, 255)

End If
Next i

ws.Sort.SortFields.Clear
ws.Sort.SortFields.Add(Range("A2"), _
xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(255, 0 _
, 0)
ws.Sort.SortFields.Add(Range("A2"), _
xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(255, _
255, 0)
ws.Sort.SortFields.Add(Range("A2"), _
xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(146, _
208, 80)

With ws.Sort

.SetRange Range("A:G")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply

End With
ws.Range("G1").Value = "Utilisation"

ws.Range("A1:G1").Interior.ColorIndex = 23
ws.Range("A1:G1").Font.Color = vbWhite
ws.Range("A:G").EntireColumn.AutoFit
ws.Range("A:G").HorizontalAlignment = xlCenter
ws.Range("A:G").VerticalAlignment = xlCenter
ws.Range("a1").CurrentRegion.Borders.LineStyle = xlNone
ws.Range("a1").CurrentRegion.Borders.LineStyle = xlContinuous
ws.Range("A1").CurrentRegion.Find("Planned De-Fleet Date").EntireColumn.NumberFormat = "dd/mm/yyyy"

Application.Goto Range("a1"), True

Next ws
Sheets("Vehicle Fleet Performance").Activate

End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Anthony47

Well-known Member
Joined
Mar 29, 2006
Messages
2,148
Would it be ok to set in Red the range before checking which colour assign? Ie, add the line marked <<< in this position
VBA Code:
'more code
ws.Range("G" & I).NumberFormat = "0.00%"
ws.Range("G" & I).Interior.Color = 255         '<<<< Red
On Error GoTo 0
'more code

Bye
 

Watch MrExcel Video

Forum statistics

Threads
1,132,646
Messages
5,654,561
Members
418,140
Latest member
ahepple86

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top