anand3dinesh
Board Regular
- Joined
- Dec 19, 2019
- Messages
- 137
- Office Version
- 365
- Platform
- 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
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