Go Premium for a chance to win a PS4. Enter to Win


Format same as range cell

Posted on 2013-01-03
Medium Priority
Last Modified: 2013-01-09
I wish to conditionally format Cells in row A to recognize the cell that matches it in the range of cells in row D and then format it the same as that matching cell in the range in row D.
i.e. A1 would be in bold if D1 were in bold. i.e. A1 would be yellow if D3 were yellow and so on A3 would stay the same as there is no match for it in the list in row D or if there is a match the formatting is the same as the original.

I would like it to only recognize cell color, font color and if the font is bold or not. but this is not necessary.

      A      B      C      D
1      L3x3x1/4                  L3x3x1/4
2      L6x6x1/4                  L4X4X1/4
3      L7x7x1/2                  L6X6X1/4

Thanks Bill
Question by:Billkronmiller
  • 6
  • 3
  • 2
LVL 50

Accepted Solution

Ingeborg Hawighorst (Microsoft MVP / EE MVE) earned 1200 total points
ID: 38742163

this cannot be done with just formulas and conditional formatting. It would require VBA. Are you comfortable with that?

cheers, teylyn

Author Comment

ID: 38742172
I am vaguely familiar with it and have some macros that were done by "Brad" at Experts many years ago. If it is not too complex that may be the way to go.

Thanks Bill

Author Comment

ID: 38742197
I could simply place a nuber in an adjacent cell and use thta to trigger the formating. Saw a 1 in row c would be a yellow highlight and a 2 would be bold. That would be much simpler.
what I really want to do is somehow do something to the cell in the range to make it recognizable and I thought formatting that cell would work but i guess not.

     A      B              C          D
1      L3x3x1/4       2       L3x3x1/4
2      L6x6x1/4                L4X4X1/4
3      L7x7x1/2       1       L6X6X1/4
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!

LVL 50
ID: 38742224
You could try this macro:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim tRow As Long

If Not Intersect(Target, Range("A:A")) Is Nothing Then
    On Error Resume Next
    Application.EnableEvents = False
    tRow = WorksheetFunction.Match(Target, Range("D:D"), 0)
    Range("D" & tRow).Copy
    Target.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
            SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
    Application.EnableEvents = True
End If

Open in new window

Copy the code above
Right-click on the sheet tab and select "View Code"
Paste the code into the big white code window.

Your idea to assign codes to determine the format would also work. You could then use conditional formatting with formulas.  

Select all cells in column A, starting with cell A1, then click the Home Ribbon > Conditional formatting > New Rule > Use a formula to determine ... and enter a formula along these lines

Apply a yellow format

Then create another rule with this formula

Apply a bold format

and so on.

cheers, teylyn
LVL 93

Expert Comment

by:Patrick Matthews
ID: 38742226

To make it work as your originally described will require VBA.  This seems to be working for me:

Sub ApplyFormats()
    Dim LastRColA As Long
    Dim LastRColD As Long
    Dim MatchRng As Range
    Dim Counter As Long
    Dim CopyFromRng As Range
    Dim CopyToRng As Range
    With ThisWorkbook.Worksheets("Sheet1")
        LastRColA = .Cells(.Rows.Count, "a").End(xlUp).Row
        LastRColD = .Cells(.Rows.Count, "d").End(xlUp).Row
        Set MatchRng = .Range("a1:a" & LastRColA)
        With .Range("d1:d" & LastRColD)
            .Interior.ColorIndex = xlColorIndexNone
            .Font.ColorIndex = xlAutomatic
            .Font.Bold = False
        End With
        For Counter = 1 To LastRColD
            Set CopyToRng = .Cells(Counter, "d")
            If CopyToRng <> 0 Then
                On Error Resume Next
                Set CopyFromRng = .Cells(Application.Match(CopyToRng.Value, MatchRng, 0), "a")
                If Err = 0 Then
                    CopyToRng.PasteSpecial xlPasteFormats
                    Application.CutCopyMode = False
                End If
                On Error GoTo 0
            End If
    End With
    MsgBox "Done"
End Sub

Open in new window

Now, your revised approach can be done using Conditional Formatting.  Which version of Excel are you using?
LVL 93

Expert Comment

by:Patrick Matthews
ID: 38742230
Seems teylyn beat me there by a few seconds :)

Author Comment

ID: 38742245
I have excel 2010. However the actual range of cells I am using are instead of D1 it is "Data!E42:E3000" and the range of cells in column is actually "TAKE OFF!$H9:$H3000".

Author Comment

ID: 38742270
It not over yet. I am heading home and will continue to work there. thanks and will talk in a bit.


Author Closing Comment

ID: 38757578
There really wasn't an answer as excel does not recognize formatting of cells. Hopefully it will in future releases. It would be very useful and save lots of formula writing and look-ups.
thanks Bill
LVL 50
ID: 38757875

there was an answer. In fact there were three:

- do it with conditional formatting with a helper cell and a code number for each format
- do it with the code matthewspatrick posted
- do it with the code I posted.

If you don't want to use VBA or the helper cell approach, then "it can't be done" is a valid answer and deserves an "A" grade, not a "B". Experts here are not responsible for the way Excel works. I appreciate that you are not happy with the way Excel works and I have similar gripes with Excel and other software. Still, if it can't be done and an Expert tells you so, it is an "A" grade.

regards, teylyn

Author Comment

ID: 38758844
Teylyn, I do apologize for the B and now that you have explained it to me I would be happy to change the grade to an A. I do find VBA to be a little cumbersome and with multiple users and constantly changing my spread sheet i would just as soon not use it. I do appreciate you input and please let me know what i can do to change your grade and in the future i will keep this in mind.

Thanks again, Bill

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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 …
Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

885 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