Color Filtered Data

bassemjohn1

Board Regular
Joined
Jun 26, 2020
Messages
51
Office Version
  1. 2016
Platform
  1. Windows
Hello All

I need to filter column M for X and highlight green the filtered data in column K, i already highlighted the filtered data in column L successfully but when i try to do the same for column K, it doesn't work and it highlight wrong cells
1542001 - 2364001 Recon June- final 5.XLSX
KLM
1Amount in local currencyRecon.Match
2-20,269.2020269.2-1x
3-21,500.0021500-1x
4-1,042.651042.65-1x
5-111,198.38111198.38-1 
6-17,000.0017000-1x
7-2,146.202146.2-1x
8-2,100.002100-1x
9-10,821.0010821-1x
10-103,949.21103949.21-1 
11-197,321.76197321.76-1 
12-15,916.1215916.12-1 
13-376,754.43376754.43-1x
14-391.05391.05-1x
15-146,771.46146771.46-1 
16-105,857.06105857.06-1 
17-4,595.124595.12-1x
18-1,051.671051.67-1x
191,221.221221.22-1 
20-50.0050-1x
21-1,051.671051.67-2x
22-3,339.003339-1 
23-2,076.922076.92-1 
24-207.38207.38-1 
25-31,442.1031442.1-1x
26-7,905.457905.45-1x
27-9,414.009414-1x
28-50.0050-2x
29-8,480.008480-1x
30-8,221.268221.26-1x
31-1,825.651825.65-1x
32-264.43264.43-1 
AEA - AEJ
Cell Formulas
RangeFormula
L2:L32L2=IF(K2<0,-K2&"-"&COUNTIF(K$2:K2,K2),K2&"-"&COUNTIF(K$2:K2,K2))
M2:M32M2=IF(COUNTIF($L$2:$L$292,L2)=2,"x","")
Cells with Conditional Formatting
CellConditionCell FormatStop If True
K:KCell ValueduplicatestextNO
L:LCell ValueduplicatestextNO


My Code :
VBA Code:
 Columns("L:M").Insert
 Range("L1").Value = "Recon."
 Range("M1").Value = "Match"
 Range("L2").Formula = "=IF(RC[-1]<0,-RC[-1]&""-""&COUNTIF(R2C[-1]:RC[-1],RC[-1]),RC[-1]&""-""&COUNTIF(R2C[-1]:RC[-1],RC[-1]))"
Range("M2").Formula = "=IF(COUNTIF(R2C12:R292C12,RC[-1])=2,""x"","""")"
Range("L2").Copy Range("L3:L" & Cells(Rows.Count, 4).End(xlUp).Row)
Range("M2").Copy Range("M3:M" & Cells(Rows.Count, 4).End(xlUp).Row)
Range("L1").Select

With Worksheets("Sheet1").Range("A1")
 .AutoFilter Field:=12, Criteria1:="-0"
 
   Range("L2", Range("L2").End(xlDown)).SpecialCells(xlCellTypeVisible).ClearContents
If ActiveSheet.AutoFilterMode Then ActiveSheet.ShowAllData
With Worksheets("Sheet1").Range("A1")
.AutoFilter Field:=13, Criteria1:="x"
    Range("L2").Select
    Range(Selection, Selection.End(xlDown)).Select
    
    ws.Range("L:L").FormatConditions.AddUniqueValues
    Set HighlightDuplicates = ws.Range("L:L").FormatConditions(1)
    
     With HighlightDuplicates
        .SetFirstPriority
        .DupeUnique = xlDuplicate
        .Font.Color = vbBlack
        .Interior.Color = 5287936
        .StopIfTrue = False
        End With


    Range("K2").Select
    Range(Selection, Selection.End(xlDown)).Select
    
    ws.Range("K:K").FormatConditions.AddUniqueValues
    Set HighlightDuplicates = ws.Range("K:K").FormatConditions(1)
    
     With HighlightDuplicates
        .SetFirstPriority
        .DupeUnique = xlDuplicate
        .Font.Color = vbBlack
        .Interior.Color = 5287936
        .StopIfTrue = False
        End With
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Why don't you use column M value as condition for formating Column K and L? It is simple isn't?
 
Upvote 0
would you please help me writing a macro for it
i tired this code

VBA Code:
'Create variables to hold the number of rows for the tabular data
Dim RRow As Long, N As Long
'Capture the number of rows within the tabular data range
RRow = ActiveSheet.UsedRange.Rows.Count
'Iterate through all the rows in the tabular data range
For N = 1 To RRow
    'Use a Select Case statement to evaluate the formatting based on column 2
    Select Case ActiveSheet.Cells(N, 13).Value
        'Turn the interior color to blue
        Case "x"
        ActiveSheet.Cells(N, 11).Interior.Color = vbGreen
        'Turn the interior color to red
        Case "x"
        ActiveSheet.Cells(N, 12).Interior.Color = vbGreen

    End Select
Next N

it only worked on column K but not L

1542001 - 2364001 Recon June- final 5.XLSX
KLM
1Amount in local currencyRecon.Match
2-20,269.2020269.2-1x
3-21,500.0021500-1x
4-1,042.651042.65-1x
5-111,198.38111198.38-1 
6-17,000.0017000-1x
7-2,146.202146.2-1x
8-2,100.002100-1x
9-10,821.0010821-1x
10-103,949.21103949.21-1 
11-197,321.76197321.76-1 
12-15,916.1215916.12-1 
13-376,754.43376754.43-1x
14-391.05391.05-1x
15-146,771.46146771.46-1 
16-105,857.06105857.06-1 
17-4,595.124595.12-1x
18-1,051.671051.67-1x
191,221.221221.22-1 
20-50.0050-1x
21-1,051.671051.67-2x
22-3,339.003339-1 
23-2,076.922076.92-1 
24-207.38207.38-1 
25-31,442.1031442.1-1x
26-7,905.457905.45-1x
27-9,414.009414-1x
AEA - AEJ
Cell Formulas
RangeFormula
L2:L27L2=IF(K2<0,-K2&"-"&COUNTIF(K$2:K2,K2),K2&"-"&COUNTIF(K$2:K2,K2))
M2:M27M2=IF(COUNTIF($L$2:$L$292,L2)=2,"x","")
 
Upvote 0
i tired this code

VBA Code:
'Create variables to hold the number of rows for the tabular data
Dim RRow As Long, N As Long
'Capture the number of rows within the tabular data range
RRow = ActiveSheet.UsedRange.Rows.Count
'Iterate through all the rows in the tabular data range
For N = 1 To RRow
    'Use a Select Case statement to evaluate the formatting based on column 2
    Select Case ActiveSheet.Cells(N, 13).Value
        'Turn the interior color to blue
        Case "x"
        ActiveSheet.Cells(N, 11).Interior.Color = vbGreen
        'Turn the interior color to red
        Case "x"
        ActiveSheet.Cells(N, 12).Interior.Color = vbGreen

    End Select
Next N

it only worked on column K but not L

1542001 - 2364001 Recon June- final 5.XLSX
KLM
1Amount in local currencyRecon.Match
2-20,269.2020269.2-1x
3-21,500.0021500-1x
4-1,042.651042.65-1x
5-111,198.38111198.38-1 
6-17,000.0017000-1x
7-2,146.202146.2-1x
8-2,100.002100-1x
9-10,821.0010821-1x
10-103,949.21103949.21-1 
11-197,321.76197321.76-1 
12-15,916.1215916.12-1 
13-376,754.43376754.43-1x
14-391.05391.05-1x
15-146,771.46146771.46-1 
16-105,857.06105857.06-1 
17-4,595.124595.12-1x
18-1,051.671051.67-1x
191,221.221221.22-1 
20-50.0050-1x
21-1,051.671051.67-2x
22-3,339.003339-1 
23-2,076.922076.92-1 
24-207.38207.38-1 
25-31,442.1031442.1-1x
26-7,905.457905.45-1x
27-9,414.009414-1x
AEA - AEJ
Cell Formulas
RangeFormula
L2:L27L2=IF(K2<0,-K2&"-"&COUNTIF(K$2:K2,K2),K2&"-"&COUNTIF(K$2:K2,K2))
M2:M27M2=IF(COUNTIF($L$2:$L$292,L2)=2,"x","")
i tried double cond. for. and it worked, Thank you so much Gnaga !!
 
Upvote 0
My proposal was this without Macro

Book5.xlsx
KLM
1Amount in local currencyRecon.Match
2-20269.220269.2-1 
3-2150021500-1 
4-1042.651042.65-1 
5-111198111198.38-1 
6-1700017000-1 
7-2146.22146.2-1 
8-21002100-1 
9-1082110821-1 
10-103949103949.21-1 
11-197322197321.76-1 
12-15916.115916.12-1 
13-376754376754.43-1 
14-391.05391.05-1 
15-146771146771.46-1 
16-105857105857.06-1 
17-4595.124595.12-1 
18-1051.671051.67-1x
191221.221221.22-1 
20-5050-1 
21-1051.671051.67-2x
22-33393339-1 
23-2076.922076.92-1 
24-207.38207.38-1 
25-31442.131442.1-1 
26-7905.457905.45-1 
27-94149414-1 
Sheet2
Cell Formulas
RangeFormula
L2:L27L2=IF(K2<0,-K2&"-"&COUNTIF(K$2:K2,K2),K2&"-"&COUNTIF(K$2:K2,K2))
M2:M27M2=IF(COUNTIF($K$2:$K$27,K2)=2,"x","")
Cells with Conditional Formatting
CellConditionCell FormatStop If True
K2:L27Expression=($M2="X")textNO
 
Upvote 0

Forum statistics

Threads
1,214,576
Messages
6,120,350
Members
448,956
Latest member
Adamsxl

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
Back
Top