Solved

Match Formatting

Posted on 2011-03-21
4
227 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 80

Expert Comment

by:byundt
Comment Utility
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
Comment Utility
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 80

Accepted Solution

by:
byundt earned 500 total points
Comment Utility
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
Comment Utility
Thank you
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now