hi,
Using macro below to sort and highlight,Having trouble with macro below :
1. Need to highlight entire row with color if matching numbers in column A
2. Need to highlight entire row with different color if matching number in column A
3. Need to highlight font only if column D(dates) and Column E(dates) if dates dont match.
Sub Format_Data()
Dim LR As Long
'Delete top 3 rows
Rows("1:3").Delete Shift:=xlUp
Cells.Select
Selection.UnMerge
'Find Last Row No.
LR = Range("A:A").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Columns("A:A").ColumnWidth = 12
Columns("B:B").ColumnWidth = 11.29
Columns("C:C").ColumnWidth = 10.86
Columns("D:D").ColumnWidth = 18.86
Columns("D:D").ColumnWidth = 23.14
Columns("E:E").Select
Selection.Delete Shift:=xlToLeft
Selection.ColumnWidth = 23.14
Columns("F:F").Select
Selection.Delete Shift:=xlToLeft
Selection.Delete Shift:=xlToLeft
Columns("G:G").ColumnWidth = 15.57
Columns("G:G").ColumnWidth = 8.43
Columns("H:H").Select
Selection.Delete Shift:=xlToLeft
Selection.ColumnWidth = 13
Selection.ColumnWidth = 7.57
Columns("I:I").Select
Selection.Delete Shift:=xlToLeft
Selection.ColumnWidth = 16.14
Columns("J:J").Select
Selection.Delete Shift:=xlToLeft
Selection.ColumnWidth = 22.71
Columns("K:K").Select
Selection.Delete Shift:=xlToLeft
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 6
Columns("L:L").ColumnWidth = 18.29
Range("L2").Select
Columns("L:L").ColumnWidth = 23.86
Columns("M:M").Select
Selection.Delete Shift:=xlToLeft
Selection.ColumnWidth = 19.14
Selection.ColumnWidth = 30.71
Selection.ColumnWidth = 39
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 8
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 10
ActiveWindow.ScrollColumn = 11
ActiveWindow.ScrollColumn = 12
Columns("N:N").Select
Selection.Delete Shift:=xlToLeft
Columns("O:O").Select
Selection.Delete Shift:=xlToLeft
Columns("P").Select
Selection.Delete Shift:=xlToLeft
Selection.ColumnWidth = 18.71
Columns("O:O").ColumnWidth = 19
Columns("Q:Q").Select
Selection.Delete Shift:=xlToLeft
Selection.ColumnWidth = 16.71
Columns("R:R").Select
Selection.Delete Shift:=xlToLeft
ActiveWindow.ScrollColumn = 13
ActiveWindow.ScrollColumn = 14
ActiveWindow.ScrollColumn = 15
ActiveWindow.ScrollColumn = 16
Selection.ColumnWidth = 23.43
Selection.ColumnWidth = 24.86
Columns("S:S").Select
Selection.Delete Shift:=xlToLeft
Columns("U:U").Select
Selection.Delete Shift:=xlToLeft
Columns("T:T").ColumnWidth = 38.29
Columns("T:T").ColumnWidth = 58.29
Columns("S:S").ColumnWidth = 23.71
ActiveWindow.ScrollColumn = 15
ActiveWindow.ScrollColumn = 14
ActiveWindow.ScrollColumn = 13
ActiveWindow.ScrollColumn = 12
ActiveWindow.ScrollColumn = 11
ActiveWindow.ScrollColumn = 10
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 8
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 1
'Sort according to Rules
Range("A1").Select
With ActiveWorkbook.Worksheets("Daily RFC Report").Sort
.SortFields.Clear
.SetRange Range("A1:T" & LR)
.SortFields.Add Key:=Range("J2:J" & LR), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
.SortFields.Add Key:=Range("A2:A" & LR), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
'Set freeze panes
Range("C2").Select
ActiveWindow.FreezePanes = True
'Add helper column & hide it
Range("U2").FormulaR1C1 = "=IF(RC[-18]<>R[-1]C[-18],NOT(R[-1]C),R[-1]C)"
Range("U2").AutoFill Destination:=Range("U2:U" & LR)
Columns("U:U").EntireColumn.Hidden = True
'Setup Conditional Formatting
Range("A2:T2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$U2=TRUE"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent6
.TintAndShade = 0.599963377788629
End With
Selection.FormatConditions(1).StopIfTrue = True
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$U2=FALSE"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent5
.TintAndShade = 0.599963377788629
End With
Selection.FormatConditions(1).StopIfTrue = True
ActiveSheet.Range(Cells(2, "A"), Cells(LR, "T")).Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=T2<>"""""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Bold = True
.Color = -16776961
End With
Selection.FormatConditions(1).StopIfTrue = True
Range("A1").Select
End Sub
Using macro below to sort and highlight,Having trouble with macro below :
1. Need to highlight entire row with color if matching numbers in column A
2. Need to highlight entire row with different color if matching number in column A
3. Need to highlight font only if column D(dates) and Column E(dates) if dates dont match.
Sub Format_Data()
Dim LR As Long
'Delete top 3 rows
Rows("1:3").Delete Shift:=xlUp
Cells.Select
Selection.UnMerge
'Find Last Row No.
LR = Range("A:A").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Columns("A:A").ColumnWidth = 12
Columns("B:B").ColumnWidth = 11.29
Columns("C:C").ColumnWidth = 10.86
Columns("D:D").ColumnWidth = 18.86
Columns("D:D").ColumnWidth = 23.14
Columns("E:E").Select
Selection.Delete Shift:=xlToLeft
Selection.ColumnWidth = 23.14
Columns("F:F").Select
Selection.Delete Shift:=xlToLeft
Selection.Delete Shift:=xlToLeft
Columns("G:G").ColumnWidth = 15.57
Columns("G:G").ColumnWidth = 8.43
Columns("H:H").Select
Selection.Delete Shift:=xlToLeft
Selection.ColumnWidth = 13
Selection.ColumnWidth = 7.57
Columns("I:I").Select
Selection.Delete Shift:=xlToLeft
Selection.ColumnWidth = 16.14
Columns("J:J").Select
Selection.Delete Shift:=xlToLeft
Selection.ColumnWidth = 22.71
Columns("K:K").Select
Selection.Delete Shift:=xlToLeft
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 6
Columns("L:L").ColumnWidth = 18.29
Range("L2").Select
Columns("L:L").ColumnWidth = 23.86
Columns("M:M").Select
Selection.Delete Shift:=xlToLeft
Selection.ColumnWidth = 19.14
Selection.ColumnWidth = 30.71
Selection.ColumnWidth = 39
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 8
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 10
ActiveWindow.ScrollColumn = 11
ActiveWindow.ScrollColumn = 12
Columns("N:N").Select
Selection.Delete Shift:=xlToLeft
Columns("O:O").Select
Selection.Delete Shift:=xlToLeft
Columns("P").Select
Selection.Delete Shift:=xlToLeft
Selection.ColumnWidth = 18.71
Columns("O:O").ColumnWidth = 19
Columns("Q:Q").Select
Selection.Delete Shift:=xlToLeft
Selection.ColumnWidth = 16.71
Columns("R:R").Select
Selection.Delete Shift:=xlToLeft
ActiveWindow.ScrollColumn = 13
ActiveWindow.ScrollColumn = 14
ActiveWindow.ScrollColumn = 15
ActiveWindow.ScrollColumn = 16
Selection.ColumnWidth = 23.43
Selection.ColumnWidth = 24.86
Columns("S:S").Select
Selection.Delete Shift:=xlToLeft
Columns("U:U").Select
Selection.Delete Shift:=xlToLeft
Columns("T:T").ColumnWidth = 38.29
Columns("T:T").ColumnWidth = 58.29
Columns("S:S").ColumnWidth = 23.71
ActiveWindow.ScrollColumn = 15
ActiveWindow.ScrollColumn = 14
ActiveWindow.ScrollColumn = 13
ActiveWindow.ScrollColumn = 12
ActiveWindow.ScrollColumn = 11
ActiveWindow.ScrollColumn = 10
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 8
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 1
'Sort according to Rules
Range("A1").Select
With ActiveWorkbook.Worksheets("Daily RFC Report").Sort
.SortFields.Clear
.SetRange Range("A1:T" & LR)
.SortFields.Add Key:=Range("J2:J" & LR), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
.SortFields.Add Key:=Range("A2:A" & LR), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
'Set freeze panes
Range("C2").Select
ActiveWindow.FreezePanes = True
'Add helper column & hide it
Range("U2").FormulaR1C1 = "=IF(RC[-18]<>R[-1]C[-18],NOT(R[-1]C),R[-1]C)"
Range("U2").AutoFill Destination:=Range("U2:U" & LR)
Columns("U:U").EntireColumn.Hidden = True
'Setup Conditional Formatting
Range("A2:T2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$U2=TRUE"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent6
.TintAndShade = 0.599963377788629
End With
Selection.FormatConditions(1).StopIfTrue = True
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$U2=FALSE"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent5
.TintAndShade = 0.599963377788629
End With
Selection.FormatConditions(1).StopIfTrue = True
ActiveSheet.Range(Cells(2, "A"), Cells(LR, "T")).Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=T2<>"""""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Bold = True
.Color = -16776961
End With
Selection.FormatConditions(1).StopIfTrue = True
Range("A1").Select
End Sub