Copy Cell color interior to another cell without effecting its contents

thequiff

New Member
Joined
Aug 29, 2012
Messages
34
Ideally, I want to avoid conditional formatting so that I can apply this. Ideally a custom Formula
Screenshot 2023-02-08 at 11.52.08.png


So above in C1 it is simply =A2
I would like to have USER formula to get the color interior of A2 and apply it to cell C2
How do I go about this?
I found this to extract the color as a decimal
Function MyBackgroundColor(cell As Range)
MyBackgroundColor = cell.Interior.Color
End Function
but the above function won't work if there is data in the cell it's getting the color from. But then I don't know how to use that color to apply to another cell.
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Try:
VBA Code:
Sub CopyColor()
    Application.ScreenUpdating = False
    Dim rng As Range
    For Each rng In Range("A2", Range("A" & Rows.Count).End(xlUp))
        rng.Offset(, 2).Interior.ColorIndex = rng.Interior.ColorIndex
    Next rng
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Try:
VBA Code:
Sub CopyColor()
    Application.ScreenUpdating = False
    Dim rng As Range
    For Each rng In Range("A2", Range("A" & Rows.Count).End(xlUp))
        rng.Offset(, 2).Interior.ColorIndex = rng.Interior.ColorIndex
    Next rng
    Application.ScreenUpdating = True
End Sub
Many Thanks. however is it possible to turn that into a user function?
When by in the formula you specific which cell to color?

=CopyIntColor("from" (A1) "to" (G9)

Something along the lines of that?
 
Upvote 0
I'm not sure but I don't think that a function can format a cell with color. Have you looked at conditional formatting?
 
Upvote 0
I'm not sure but I don't think that a function can format a cell with color. Have you looked at conditional formatting?
I'm trying to do this route and avoid conditional formatting as I need to apply it to an existing sheet.
 
Upvote 0
Right click on tab' name, then click ViewCode then paste below code into. This trigger any change in column C, from C2 to C7.
Now in C2, input:
=A2
Then drag down
VBA Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Application.Volatile
Dim cell As Range
If Intersect(Target, Range("C2:C7")) Is Nothing Then Exit Sub
For Each cell In Target
    If cell.Value = cell.Offset(, -2).Value Then cell.Interior.Color = cell.Offset(, -2).Interior.Color
Next
End Sub
 
Upvote 0
Right click on tab' name, then click ViewCode then paste below code into. This trigger any change in column C, from C2 to C7.
Now in C2, input:
=A2
Then drag down
VBA Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Application.Volatile
Dim cell As Range
If Intersect(Target, Range("C2:C7")) Is Nothing Then Exit Sub
For Each cell In Target
    If cell.Value = cell.Offset(, -2).Value Then cell.Interior.Color = cell.Offset(, -2).Interior.Color
Next
End Sub
Thats great thanks, obviously this leads to another question now I need to apply the code.

If I do the same but on Sheet 2 but needs to reference the cell it came from on sheet 1?
This is the formula in one of the cells
=IF(OFFSET(SKUs!B2,'1'!J2,0)=0,"",(OFFSET(SKUs!B2,'1'!J2,0)))

So would need to get the colour from sheet "SKU's" on B2


Link to barcodes Xls (We transfer)
 
Upvote 0

Forum statistics

Threads
1,214,822
Messages
6,121,767
Members
449,049
Latest member
greyangel23

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