Trying to concatenate based on font color

J

jeremiah

I have imported a csv file that splits the names into 3 different colomns. I
am trying to merge the names back together but only when it meets certain
criteria. Cannot figure out how to make the following formula work only on
cells that have a font ColorIndex of 3. Have searched but can't find quite
the right answer. Thanks in advance for your help.

Sub ConcatColor()
lastrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lastrow '<<assumes header row
Range("P" & i) = Cells(i, 7) & " " & Cells(i, 8) & " " & Cells(i, 9)
Next
End Sub
 
J

JLGWhiz

Need value.
Range("P" & i) = Cells(i, 7).Value & " " & Cells(i, 8).Value & " " &
Cells(i, 9).Value
 
M

Mike H

Hi,

I'm not sure which cells you want to check the colorindex of but this may
get you going in the right direction

For i = 2 To lastrow '<<assumes header row
If Range("P" & i).Interior.ColorIndex = 3 Then
Range("P" & i) = Cells(i, 7) & " " & Cells(i, 8) & " " & Cells(i, 9)
Next


Mike
 
J

jeremiah

Thanks so much, I knew it was a very simple fix. I did have a compile error
but inserted an End If and works perfectly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top