Copying cell background format in formula

sharshra

Active Member
Joined
Mar 20, 2013
Messages
413
Office Version
  1. 365
I have few cells color coded in the source table. When these cells are referred in another table, I would like to get the same background format. Is that possible? Can the experts advise please?

Example - Few cells are color coded in the source table. When I refer these in the new table, it should get the same background color as that of source table.

Source table:
excel problems.xlsx
P
213
22d3
239
242
2554
267n
Sheet2


New table:
excel problems.xlsx
R
2154
229
232
247n
25ab
Sheet2
 
Let me be as clear as possible about my question.

To provide VBA code to solve this, I need to know exactly which cells are in the first range, and exactly which cells are in the second range. Your example shows that the first range is P21:P26, but you need to give us the full range of cells in the source table. Same for the table where you will be entering data.
 
Upvote 0

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
I have no control on the conditional format done in the source file.
:confused: Earlier you said
First table has no conditional formatting.
I will assume no conditional formatting, just formatting.

As Jeff has pointed out you still have not detailed just what cells are (or might be) in either range. I have assumed the first range is the whole of (or anywhere in) column P and the second range is the whole of (or anywhere in) column R.

This is a worksheet 'event' code so to implement ..
1. Right click the sheet name tab and choose "View Code".
2. Copy and Paste the code below into the main right hand pane that opens at step 1.
3. Close the Visual Basic window & test by entering/deleting/editing values in column R, given the original values/colours are already in column P.
4. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm).

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim Changed As Range, c As Range, rFound As Range
  
  Set Changed = Intersect(Target, Columns("R"))
  If Not Changed Is Nothing Then
    For Each c In Changed
      Set rFound = Columns("P").Find(What:=c.Value, LookAt:=xlWhole, MatchCase:=True)
      If rFound Is Nothing Then
        c.Interior.Color = xlNone
      Else
        c.Interior.Color = IIf(rFound.Interior.Color = 16777215, xlNone, rFound.Interior.Color)
      End If
    Next c
  End If
End Sub
 
Upvote 0
Solution
I do not know the criteria that you use to create the new table.

You may want to look at Data | Sort & Filter | Advanced

I used the built in feature of Excel and moved a portion of the range to a new range.

T202501a.xlsm
PQR
18
19
20
2139
22d32
23954
2427n
2554
267n
27
28
6c
 
Upvote 0

Forum statistics

Threads
1,225,729
Messages
6,186,692
Members
453,369
Latest member
positivemind

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