Solved

Match Formatting

Posted on 2011-03-21
4
233 Views
Last Modified: 2012-05-11
I'm using the code I found on this site below to match the formatting in column CH to column A where the values match. But it just removes the formatting in both columns.  Any ideas?
Sub Colors()
Dim cel As Range, celA As Range, rgA As Range, rgC As Range
Application.ScreenUpdating = False
Set rgA = Range("A1")   'First cell with names in column A
'Set rgA = Range(Sheets("FRBSample").[A2])   'First cell with names in column A
Set rgA = Range(rgA, Cells(Rows.Count, rgA.Column).End(xlUp))
'Set rgC = Range(Sheets("FATIMA").[A2])   'First cell with names in column C
Set rgC = Range("CH1")
Set rgC = Range(rgC, Cells(Rows.Count, rgC.Column).End(xlUp))
 
For Each cel In rgC.Cells
    If cel <> "" Then
        Set celA = Nothing
        Set celA = rgA.Find(cel, MatchCase:=False, Lookat:=xlWhole)
        If Not celA Is Nothing Then cel.Interior.ColorIndex = celA.Interior.ColorIndex
    End If
Next
Application.ScreenUpdating = True
End Sub

Open in new window

0
Comment
Question by:error_prone
  • 2
  • 2
4 Comments
 
LVL 81

Expert Comment

by:byundt
ID: 35183064
Is the source of the formatting in column CH or column A? As written, your code thinks the format source is in column A. If you would like the format source to be in column CH, then change statement 15 to:
        If Not celA Is Nothing Then celA.Interior.ColorIndex = cel.Interior.ColorIndex

Open in new window

Brad
0
 

Author Comment

by:error_prone
ID: 35183170
Some of the colors don't match exactly and I am wondering if the original worksheet where the color coding came from had a different color palette.  How do you copy the color palette between 2 Excel 2007 workbooks?  The option used to be under the Color tab in Excel 2003...
0
 
LVL 81

Accepted Solution

by:
byundt earned 500 total points
ID: 35183395
If you record a macro setting the color, you will see properties like cel.Interior.TintAndShade and .ThemeColor. You also have the option of setting the Color property instead of the ColorIndex. The code below sets column A color equal to that in column CH. It uses ThemeColor if it applies and Color if it does not.
Sub Colors()
Dim cel As Range, celA As Range, rgA As Range, rgC As Range
Application.ScreenUpdating = False
Set rgA = Range("A1")   'First cell with names in column A
'Set rgA = Range(Sheets("FRBSample").[A2])   'First cell with names in column A
Set rgA = Range(rgA, Cells(Rows.Count, rgA.Column).End(xlUp))
'Set rgC = Range(Sheets("FATIMA").[A2])   'First cell with names in column C
Set rgC = Range("CH1")
Set rgC = Range(rgC, Cells(Rows.Count, rgC.Column).End(xlUp))
 
For Each cel In rgC.Cells
    If cel <> "" Then
        Set celA = Nothing
        Set celA = rgA.Find(cel, MatchCase:=False, Lookat:=xlWhole)
        'If Not celA Is Nothing Then cel.Interior.ColorIndex = celA.Interior.ColorIndex
        If Not celA Is Nothing Then
            On Error Resume Next
            celA.Interior.Color = cel.Interior.Color
            celA.Interior.ThemeColor = cel.Interior.ThemeColor
            celA.Interior.TintAndShade = cel.Interior.TintAndShade
            On Error GoTo 0
        End If
    End If
Next
Application.ScreenUpdating = True
End Sub

Open in new window


Brad
0
 

Author Closing Comment

by:error_prone
ID: 35183448
Thank you
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question