Hello, Running a macro to sort data(numbers) in column A and applying FILTERS to remove data from column B and after filtering trying to highlight entire row with group of matched numbers in column A with alternate color...
With macro below :
Its highlighting matched numbers first and then filter is applied.
Can i get help in first filter is applied and then on active sheet highlights can run, so tht 2 colors are NOT mixed AND MISSED.
Sub test()
'
' test
'
'
Rows("1:3"
.Select
Selection.Delete Shift:=xlUp
Cells.Select
Selection.UnMerge
Range("A3"
.Select
Columns("A:A"
.ColumnWidth = 11.29
Columns("B:B"
.ColumnWidth = 12
Columns("C:C"
.Select
Selection.Delete Shift:=xlToLeft
Columns("C:C"
.EntireColumn.AutoFit
Columns("D:D"
.Select
Selection.Delete Shift:=xlToLeft
Columns("D:D"
.EntireColumn.AutoFit
Columns("E:E"
.Select
Selection.Delete Shift:=xlToLeft
Selection.Delete Shift:=xlToLeft
Columns("F:F"
.EntireColumn.AutoFit
Columns("G:G"
.Select
Selection.Delete Shift:=xlToLeft
Columns("G:G"
.EntireColumn.AutoFit
Columns("H:H"
.Select
Selection.Delete Shift:=xlToLeft
Columns("H:H"
.EntireColumn.AutoFit
Columns("I:I"
.Select
Selection.Delete Shift:=xlToLeft
Columns("I:I"
.EntireColumn.AutoFit
Columns("J:J"
.Select
Selection.Delete Shift:=xlToLeft
Columns("K:K"
.EntireColumn.AutoFit
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 8
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 10
Columns("L:L"
.Select
Selection.Delete Shift:=xlToLeft
Columns("L:L"
.EntireColumn.AutoFit
Selection.ColumnWidth = 33.14
Columns("M:M"
.Select
Selection.Delete Shift:=xlToLeft
Selection.ColumnWidth = 14.29
Columns("N:N"
.Select
Selection.Delete Shift:=xlToLeft
Columns("O:O"
.Select
Selection.Delete Shift:=xlToLeft
Columns("O:O"
.EntireColumn.AutoFit
Columns("P
"
.Select
Selection.Delete Shift:=xlToLeft
Columns("Q:Q"
.Select
Selection.Delete Shift:=xlToLeft
Columns("Q:Q"
.EntireColumn.AutoFit
Columns("R:R"
.Select
Selection.Delete Shift:=xlToLeft
ActiveWindow.SmallScroll ToRight:=3
Columns("S:S"
.Select
Selection.ColumnWidth = 40.43
Selection.ColumnWidth = 49.14
Selection.ColumnWidth = 61.71
Columns("T:T"
.Select
Selection.Delete Shift:=xlToLeft
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
Cells.Select
ActiveWorkbook.Worksheets("Daily RFC Report"
.Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Daily RFC Report"
.Sort.SortFields.Add Key:=Range( _
"I2:I373"
, SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Daily RFC Report"
.Sort.SortFields.Add Key:=Range( _
"A2:A373"
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("Daily RFC Report"
.Sort
.SetRange Rows("1:373"
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Rows("1:1"
.Select
Selection.AutoFilter
ActiveSheet.Range("$1:$370"
.AutoFilter Field:=9, Operator:=xlFilterValues _
, Criteria2:=Array(0, "2/12/2013"
ActiveSheet.Range("$1:$370"
.AutoFilter Field:=6, Criteria1:=Array( _
"Critical", "Major", "Minor"
, Operator:=xlFilterValues
ActiveSheet.Range("$1:$370"
.AutoFilter Field:=5, Criteria1:=Array( _
"Approved", "Open-Partially Completed", "Under Review"
, Operator:= _
xlFilterValues
Cells.Select
Selection.RowHeight = 20.25
Range("C2"
.Select
ActiveWindow.FreezePanes = True
ActiveWindow.SmallScroll Down:=-12
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 8
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 10
ActiveWindow.ScrollColumn = 11
ActiveWindow.ScrollColumn = 12
ActiveWindow.ScrollColumn = 13
ActiveWindow.ScrollColumn = 14
ActiveWindow.ScrollColumn = 15
ActiveWindow.ScrollColumn = 16
ActiveWindow.ScrollColumn = 15
ActiveWindow.ScrollColumn = 14
ActiveWindow.ScrollColumn = 13
ActiveWindow.ScrollColumn = 12
ActiveWindow.ScrollColumn = 8
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 3
Range("C5"
.Select
ActiveWindow.SmallScroll Down:=-6
Range("A2"
.Select
For Each sht In ActiveWorkbook.Sheets
If sht.Visible Then sht.Activate 'only processes visible sheets in a book
Range("A2:A2000"
.Select 'assumes column A is the column you're interested in
'blah4 'calls previous macro
Next sht
If Selection.Areas.Count > 1 Then Exit Sub 'ensures only one contiguous block selected
HighlightOn = False 'this is flipped true/false everytime a new value is encountered
StartRow = Selection.Row 'First row of selection
EndRow = StartRow + Selection.Rows.Count - 1 'last row of selection
mycolumn = Selection.Column 'leftmost column of selection
FromRow = StartRow 'FromRow is the first row of a new value encountered
Do
r = 1 'holds the number of cells found with a similar value
Do Until Cells(FromRow, mycolumn).Value <> Cells(FromRow, mycolumn).Offset(r).Value Or FromRow + r > EndRow 'comes out of loop if different value encountered or end of selection reached
r = r + 1
Loop 'this loop exits when a different value is encountered
If HighlightOn Then 'highlight the rows
Cells(FromRow, mycolumn).Resize(r).EntireRow.Interior.ColorIndex = 35
HighlightOn = Not HighlightOn 'flip the highlight
Else
HighlightOn = Not HighlightOn 'flip the highlight
End If
FromRow = FromRow + r 'set Fromrow to be the beginning of the next block of cells
Loop Until FromRow > EndRow 'stop when the bottom of the original selection is reached
End Sub
EXAMPLE: After running above macro
[pre]
[/pre]
With macro below :
Its highlighting matched numbers first and then filter is applied.
Can i get help in first filter is applied and then on active sheet highlights can run, so tht 2 colors are NOT mixed AND MISSED.
Sub test()
'
' test
'
'
Rows("1:3"
Selection.Delete Shift:=xlUp
Cells.Select
Selection.UnMerge
Range("A3"
Columns("A:A"
Columns("B:B"
Columns("C:C"
Selection.Delete Shift:=xlToLeft
Columns("C:C"
Columns("D:D"
Selection.Delete Shift:=xlToLeft
Columns("D:D"
Columns("E:E"
Selection.Delete Shift:=xlToLeft
Selection.Delete Shift:=xlToLeft
Columns("F:F"
Columns("G:G"
Selection.Delete Shift:=xlToLeft
Columns("G:G"
Columns("H:H"
Selection.Delete Shift:=xlToLeft
Columns("H:H"
Columns("I:I"
Selection.Delete Shift:=xlToLeft
Columns("I:I"
Columns("J:J"
Selection.Delete Shift:=xlToLeft
Columns("K:K"
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 8
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 10
Columns("L:L"
Selection.Delete Shift:=xlToLeft
Columns("L:L"
Selection.ColumnWidth = 33.14
Columns("M:M"
Selection.Delete Shift:=xlToLeft
Selection.ColumnWidth = 14.29
Columns("N:N"
Selection.Delete Shift:=xlToLeft
Columns("O:O"
Selection.Delete Shift:=xlToLeft
Columns("O:O"
Columns("P
Selection.Delete Shift:=xlToLeft
Columns("Q:Q"
Selection.Delete Shift:=xlToLeft
Columns("Q:Q"
Columns("R:R"
Selection.Delete Shift:=xlToLeft
ActiveWindow.SmallScroll ToRight:=3
Columns("S:S"
Selection.ColumnWidth = 40.43
Selection.ColumnWidth = 49.14
Selection.ColumnWidth = 61.71
Columns("T:T"
Selection.Delete Shift:=xlToLeft
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
Cells.Select
ActiveWorkbook.Worksheets("Daily RFC Report"
ActiveWorkbook.Worksheets("Daily RFC Report"
"I2:I373"
xlSortNormal
ActiveWorkbook.Worksheets("Daily RFC Report"
"A2:A373"
xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("Daily RFC Report"
.SetRange Rows("1:373"
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Rows("1:1"
Selection.AutoFilter
ActiveSheet.Range("$1:$370"
, Criteria2:=Array(0, "2/12/2013"
ActiveSheet.Range("$1:$370"
"Critical", "Major", "Minor"
ActiveSheet.Range("$1:$370"
"Approved", "Open-Partially Completed", "Under Review"
xlFilterValues
Cells.Select
Selection.RowHeight = 20.25
Range("C2"
ActiveWindow.FreezePanes = True
ActiveWindow.SmallScroll Down:=-12
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 8
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 10
ActiveWindow.ScrollColumn = 11
ActiveWindow.ScrollColumn = 12
ActiveWindow.ScrollColumn = 13
ActiveWindow.ScrollColumn = 14
ActiveWindow.ScrollColumn = 15
ActiveWindow.ScrollColumn = 16
ActiveWindow.ScrollColumn = 15
ActiveWindow.ScrollColumn = 14
ActiveWindow.ScrollColumn = 13
ActiveWindow.ScrollColumn = 12
ActiveWindow.ScrollColumn = 8
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 3
Range("C5"
ActiveWindow.SmallScroll Down:=-6
Range("A2"
For Each sht In ActiveWorkbook.Sheets
If sht.Visible Then sht.Activate 'only processes visible sheets in a book
Range("A2:A2000"
'blah4 'calls previous macro
Next sht
If Selection.Areas.Count > 1 Then Exit Sub 'ensures only one contiguous block selected
HighlightOn = False 'this is flipped true/false everytime a new value is encountered
StartRow = Selection.Row 'First row of selection
EndRow = StartRow + Selection.Rows.Count - 1 'last row of selection
mycolumn = Selection.Column 'leftmost column of selection
FromRow = StartRow 'FromRow is the first row of a new value encountered
Do
r = 1 'holds the number of cells found with a similar value
Do Until Cells(FromRow, mycolumn).Value <> Cells(FromRow, mycolumn).Offset(r).Value Or FromRow + r > EndRow 'comes out of loop if different value encountered or end of selection reached
r = r + 1
Loop 'this loop exits when a different value is encountered
If HighlightOn Then 'highlight the rows
Cells(FromRow, mycolumn).Resize(r).EntireRow.Interior.ColorIndex = 35
HighlightOn = Not HighlightOn 'flip the highlight
Else
HighlightOn = Not HighlightOn 'flip the highlight
End If
FromRow = FromRow + r 'set Fromrow to be the beginning of the next block of cells
Loop Until FromRow > EndRow 'stop when the bottom of the original selection is reached
End Sub
EXAMPLE: After running above macro
[pre]
Code:
COLUMN A - COLUMN B
1111 - ABCD (no highlight)
1111 -CDEF (no highlight)
2222 - AFGD (Highlighted row with green) " Here if filter applied to column B to remove AFGD and FDERF" (2222 is hidden and active sheet shows 1111grp and 3333grp with no highlights and could be missed)
2222 - FDERF (Highlighted row with green)
3333 -dfge(no highlight)
3333 -fegr(no highlight)