Find same value and Changing a cell & tex color WITHOUT using Conditional Formatting

Dsunil05

New Member
Joined
Feb 20, 2015
Messages
34
Office Version
  1. 2021
  2. 2019
  3. 2013
  4. 2007
  5. 2003 or older
Platform
  1. Windows
12
1921
252931
3233343637394450535566747577
0813161822233139454752596470717273747779
.
.
.
.
.
.
.
.
.
.
.
.
.
0309101113181927353744505759657072767980
0205111417283233373842475963647173747778
03
06080913212430313638424954596570727579

<tbody>
</tbody>

data range A1:T27
i want to find out same number And change their "cell color and text color" in data range A1:T26 of row no 27's 20 number in pink colour.
Without using Conditional Formatting
Because i copy it and use it to another data set in same worksheet e.g. range U1:AO27
In MS Excel 2007
Thanks
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
1. Can you confirm whether A1:T27 contains any formulas or not? If so, which cells?

2. Are the values like 08 text "08" or just the number 8 with custom formatting to show the leading zero?
 
Last edited:
Upvote 0
1. Can you confirm whether A1:T27 contains any formulas or not? If so, which cells?

2. Are the values like 08 text "08" or just the number 8 with custom formatting to show the leading zero?


1. No, there is not any formulas. I am doing it manually

2. the values like 08 Number "08"
 
Last edited:
Upvote 0
2. the values like 08 Number "08"
That is not clear to me. In your image, cell A2 shows "08" If you go to a blank cell and put this formula, what does it return?
=ISNUMBER(A2)
 
Upvote 0
It returns "TRUE"
OK, try this macro on a copy of your workbook.
Code:
Sub MarkMatches()
  Dim d As Object
  Dim a As Variant, b As Variant
  Dim Clr As Long, i As Long, j As Long, rws As Long, cols As Long
  
  Set d = CreateObject("Scripting.Dictionary")
  Application.ScreenUpdating = False
  With Range("A1:T27")
    Clr = .Cells(.Rows.Count, 1).Font.Color
    a = .Value
    rws = UBound(a, 1)
    cols = UBound(a, 2)
    ReDim b(1 To rws - 1, 1 To cols)
    For j = 1 To cols
      d(a(rws, j)) = 1
    Next j
    For i = 1 To rws - 1
      For j = 1 To cols
        If d(a(i, j)) = 1 Then b(i, j) = 1
      Next j
    Next i
    .Font.Color = 0
    .Value = b
    .SpecialCells(xlConstants).Font.Color = Clr
    .Value = a
  End With
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
not working
same no of range A27:T27 in Between rang A1:T26 number color not change
not finding duplicate
 
Upvote 0
OK, try this macro on a copy of your workbook.
Code:
Sub MarkMatches()
  Dim d As Object
  Dim a As Variant, b As Variant
  Dim Clr As Long, i As Long, j As Long, rws As Long, cols As Long
  
  Set d = CreateObject("Scripting.Dictionary")
  Application.ScreenUpdating = False
  With Range("A1:T27")
    Clr = .Cells(.Rows.Count, 1).Font.Color
    a = .Value
    rws = UBound(a, 1)
    cols = UBound(a, 2)
    ReDim b(1 To rws - 1, 1 To cols)
    For j = 1 To cols
      d(a(rws, j)) = 1
    Next j
    For i = 1 To rws - 1
      For j = 1 To cols
        If d(a(i, j)) = 1 Then b(i, j) = 1
      Next j
    Next i
    .Font.Color = 0
    .Value = b
    .SpecialCells(xlConstants).Font.Color = Clr
    .Value = a
  End With
  Application.ScreenUpdating = True
End Sub
If your interpretation of what the OP wanted is correct, then your macro can be written more compactly (it may even be faster) this way...
Code:
[table="width: 500"]
[tr]
	[td]Sub MarkMatches()
  Dim C As Long
  Application.ReplaceFormat.Clear
  For C = 1 To 20
    Application.ReplaceFormat.Font.Color = Cells(27, 1).Font.Color
    Range("A1:T26").Replace Cells(27, C), "", xlWhole, searchformat:=False, ReplaceFormat:=True
  Next
End Sub[/td]
[/tr]
[/table]
However, I read the OP's request differently. I took the text snippet "And change their 'cell color and text color'" from his original post to mean the each cell in A27:T27 has a different interior and font color (even though his posted table shows all the interiors/fonts the same) and that he wants those copied into the matching cells. Here is my code for that interpretation of the OP's request...
Code:
[table="width: 500"]
[tr]
	[td]Sub MatchNumbersCopyFormats()
  Dim C As Long
  Application.ReplaceFormat.Clear
  For C = 1 To 20
    Application.ReplaceFormat.Interior.Color = Cells(27, C).Interior.Color
    Application.ReplaceFormat.Font.Color = Cells(27, C).Font.Color
    Range("A1:T26").Replace Cells(27, C), "", xlWhole, SearchFormat:=False, ReplaceFormat:=True
  Next
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
If your interpretation of what the OP wanted is correct, then your macro can be written more compactly (it may even be faster) this way...
Code:
[table="width: 500"]
[tr]
	[td]Sub MarkMatches()
  Dim C As Long
  Application.ReplaceFormat.Clear
  For C = 1 To 20
    Application.ReplaceFormat.Font.Color = Cells(27, 1).Font.Color
    Range("A1:T26").Replace Cells(27, C), "", xlWhole, searchformat:=False, ReplaceFormat:=True
  Next
  [B][COLOR="#FF0000"]Application.ReplaceFormat.Clear[/COLOR][/B]
End Sub[/td]
[/tr]
[/table]
However, I read the OP's request differently. I took the text snippet "And change their 'cell color and text color'" from his original post to mean the each cell in A27:T27 has a different interior and font color (even though his posted table shows all the interiors/fonts the same) and that he wants those copied into the matching cells. Here is my code for that interpretation of the OP's request...
Code:
[table="width: 500"]
[tr]
	[td]Sub MatchNumbersCopyFormats()
  Dim C As Long
  Application.ReplaceFormat.Clear
  For C = 1 To 20
    Application.ReplaceFormat.Interior.Color = Cells(27, C).Interior.Color
    Application.ReplaceFormat.Font.Color = Cells(27, C).Font.Color
    Range("A1:T26").Replace Cells(27, C), "", xlWhole, SearchFormat:=False, ReplaceFormat:=True
  Next
  [B][COLOR="#FF0000"]Application.ReplaceFormat.Clear[/COLOR][/B]
End Sub[/td]
[/tr]
[/table]
I forgot to include the "clean up" code line I show in red above. It is not critical to the operation of the code, rather, it is a kindness to the OP for the next time he uses Excel's Find dialog box. The VBA Replace function and Excel's Find/Replace dialog box share the same search and replace format criteria, so if we don't clean up our code as above, any search and/or replace format criteria we set in our code would be "remembered" by Excel the next time the Find/Replace dialog box is called and, hence, be in effect even if the OP did not realize it.
 
Upvote 0
I forgot to include the "clean up" code line I show in red above. It is not critical to the operation of the code, rather, it is a kindness to the OP for the next time he uses Excel's Find dialog box. The VBA Replace function and Excel's Find/Replace dialog box share the same search and replace format criteria, so if we don't clean up our code as above, any search and/or replace format criteria we set in our code would be "remembered" by Excel the next time the Find/Replace dialog box is called and, hence, be in effect even if the OP did not realize it.

still not working

how post the screen shot of my manual work
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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