Solved

Match Formatting

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
usage of ms/excell 3d maps in ms/access 2016 6 42
need copy macro to select range to copy 23 48
Excel (XLSM) on iPad 3 33
Excel - IF criterion 2 22
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

739 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