Formula based on cell formatting

Miguelluis

New Member
Joined
Jan 29, 2013
Messages
45
Hi,

I've got a sheet with data as follows

[TABLE="width: 500"]
<tbody>[TR]
[TD]Client[/TD]
[TD]Name 1[/TD]
[TD]Name 2[/TD]
[TD]Name 3[/TD]
[/TR]
[TR]
[TD]1234[/TD]
[TD]Passport[/TD]
[TD]DL[/TD]
[TD]Utility[/TD]
[/TR]
[TR]
[TD]456[/TD]
[TD]Passport[/TD]
[TD]DL
[/TD]
[TD]Utility[/TD]
[/TR]
[TR]
[TD]778[/TD]
[TD]Passport[/TD]
[TD]DL[/TD]
[TD]Utility[/TD]
[/TR]
</tbody>[/TABLE]

I wanted to concatenate only if the cells or font is formatted with the colour red and list the items in separate lines, like below:

[TABLE="width: 500"]
<tbody>[TR]
[TD]1234[/TD]
[TD]-Passport
-DL
-Utility[/TD]
[/TR]
[TR]
[TD]456[/TD]
[TD]-Passport[/TD]
[/TR]
[TR]
[TD]778[/TD]
[TD]-DL
-Utility[/TD]
[/TR]
</tbody>[/TABLE]

Assuming that the above correspond to the cells that were highlighted.

Is there a way of doing this?
Thanks
Miguel
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Not without VBA, I believe.
Native Excel functions run on values, not formatting.

However, I do not understand your example. I do not see anything highlighted in red, so I am afraid that your example isn't real clear.
 
Upvote 0
Not without VBA, I believe.
Native Excel functions run on values, not formatting.

However, I do not understand your example. I do not see anything highlighted in red, so I am afraid that your example isn't real clear.

Hi, Was having issues with highlighting.
[TABLE="width: 414"]
<colgroup><col><col><col><col></colgroup><tbody>[TR]
[TD]Client[/TD]
[TD]Name 1[/TD]
[TD]Name 2[/TD]
[TD]Name 3[/TD]
[/TR]
[TR]
[TD]1234[/TD]
[TD]Passport[/TD]
[TD]DL[/TD]
[TD]Utility[/TD]
[/TR]
[TR]
[TD]456[/TD]
[TD]Passport[/TD]
[TD]DL[/TD]
[TD]Utility[/TD]
[/TR]
[TR]
[TD]778[/TD]
[TD]Passport[/TD]
[TD]DL[/TD]
[TD]Utility[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
So, is VBA an acceptable solution for you?
Do you want this to happen in the same place, or on another sheet?
If in the same place, should the unhighlighted values simply be erased?
What if a line has a client, but no highlighted items? Do you want to show that Client code, or should that whole line be removed?
 
Upvote 0
VBA could work, I want it to pull the data to a separate sheet if highlighted only. Any cells that are not highlighted that client code/line doesn't pull through the new sheet.
 
Upvote 0
I think this code should do what you want. You may just need to change the two sheet names at the top of the code.
Code:
Sub MyCopyMacro()

    Dim srcSht As Worksheet
    Dim dstSht As Worksheet
    Dim lr As Long
    Dim r As Long
    Dim nr As Long
    Dim c As Long
    Dim client As String
    Dim nme As String
    Dim ct As Long
        
'   Set source and desination sheets
    Set srcSht = Sheets("Sheet1")
    Set dstSht = Sheets("Sheet2")
    
    Application.ScreenUpdating = False
    
'   Put headers in destination sheet
    dstSht.Range("A1") = "Client"
    dstSht.Range("B1") = "Name"
    
'   Find last row with data in column A on source sheet
    lr = srcSht.Cells(Rows.Count, "A").End(xlUp).Row
    
'   Loop through all rows from row 2 to end in source sheete
    For r = 2 To lr
        client = srcSht.Cells(r, "A")
'       Loop through columns 2-4
        ct = 0
        For c = 2 To 4
'           See if any fonts are red
            If srcSht.Cells(r, c).Font.Color = vbRed Then
                nme = srcSht.Cells(r, c)    'capture name
                nr = dstSht.Cells(Rows.Count, "B").End(xlUp).Row + 1    'capture new row
                ct = ct + 1     'capture count for this client
'               Populate client on destination sheet if first match for this client
                If ct = 1 Then dstSht.Cells(nr, "A") = client
'               Populate name on destination sheet
                dstSht.Cells(nr, "B") = nme
            End If
        Next c
    Next r
    
    Application.ScreenUpdating = True
                        
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top