Solved

Match Formatting

Posted on 2011-03-21
4
235 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

707 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