Copy color of cell by value

arthur_w

New Member
Joined
May 12, 2021
Messages
16
Office Version
  1. 365
Platform
  1. Windows
I have a collumn of values 100, 101, 102 etc, and i want their color to automatically match to the values in another worksheet (but this values are in a matrix...)
I had:
"Me.Range("A3").Interior.Color = Worksheets("WS1").Range("B6").Interior.Color" for each one, but thats an awfull lot of repetition

Any ideia on how to just 'search all column values in matrix and match colors'?

Thanks!
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Me.Range("A3").Interior.Color = Worksheets("LeChaim").Range("B6:E14").Find(Me.Range("A4")).Interior.Color

Slightly updated for it to search for it self.. but miss how to do the loop
 
Upvote 0
Sub Worksheet_SelectionChange(ByVal Target As Range)
For c = Range("A3:A38").Row To (Range("A3:A38").Row + Range("A3:A38").Rows.Count - 1)
Me.Range("A" & c).Interior.Color = Worksheets("WORKSHEET").Range("B6:E14").Find(Me.Range("A" & c)).Interior.Color
Next c
End Sub



Who would have thought it... never had written before, probably dirty because of taking out the row and then adding A after, but well, it works
 
Upvote 0
Getting it to work at all is always the first step! Well done! However, it can be improved a bit:

VBA Code:
For Each c in Range("A3:A38")
    c.Interior.Color = Worksheets("WORKSHEET").Range("B6:E14").Find(c.Value).Interior.Color
Next c
 
Upvote 0
Getting it to work at all is always the first step! Well done! However, it can be improved a bit:

VBA Code:
For Each c in Range("A3:A38")
    c.Interior.Color = Worksheets("WORKSHEET").Range("B6:E14").Find(c.Value).Interior.Color
Next c

Thanks for cleaning it up, i have finalizedit to the full purpose of the initial question and already added it to it:

Sub Worksheet_SelectionChange(ByVal Target As Range)

'Ranges so i can apply it to different worksheets:

Dim Rows As Range
Set Rows = Range("A2:A37")
Dim Columns As Range
Set Columns = Range("B1:G1")
Dim matrix As Range
Set matrix = Sheets("WorkSheet").Range("B6:E14")

'turns colors into the same

For Each c In Rows
c.Interior.Color = matrix.Find(c.Value).Interior.Color
Next c

'Stores date in the correct cell based on color change and if it hasnt any data on (so that it doesnt keep rewritting everytime it runs, and doesnt errase manual inputs)

For Each a In Columns
For Each b In Rows
If a.Interior.Color = b.Interior.Color And IsEmpty(Cells(b.Row, a.Column)) Then
Cells(b.Row, a.Column).Value = Date
End If
Next b
Next a

End Sub
 
Upvote 0
Solution
I have a collumn of values 100, 101, 102 etc, and i want their color to automatically match to the values in another worksheet (but this values are in a matrix...)
I had:
"Me.Range("A3").Interior.Color = Worksheets("WS1").Range("B6").Interior.Color" for each one, but thats an awfull lot of repetition

Any ideia on how to just 'search all column values in matrix and match colors'?

Thanks!
Sub RectangleRoundedCorners1_Click()
Dim FirstMatch As Long
Dim SecondMatch As Long
Dim RowCt As Long
Dim CIndex
RowCt = Sheets("Sheet1").Range("D2").End(xlDown).Row
For FirstMatch = 2 To RowCt
For SecondMatch = FirstMatch + 1 To RowCt
If Sheets("Sheet1").Range("D" & FirstMatch).Value = Sheets("Sheet1").Range("D" & SecondMatch).Value Then
Sheets("Sheet1").Range("D" & FirstMatch).Interior.ColorIndex = SecondMatch
Sheets("Sheet1").Range("D" & SecondMatch).Interior.ColorIndex = SecondMatch
End If
Next SecondMatch
Next FirstMatch
End Sub
 

Attachments

  • ExcelColorMatch.PNG
    ExcelColorMatch.PNG
    4.8 KB · Views: 1
Upvote 0

Forum statistics

Threads
1,214,864
Messages
6,121,981
Members
449,058
Latest member
oculus

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