Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Match Formatting

Posted on 2011-03-21
4
Medium Priority
?
240 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 2000 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

Independent Software Vendors: 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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

604 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