copy contents including colour

G

gramps

Hi
In cells A1:B73 I have a list of contacts which are colour coded. What I
want to be able to do is to be able to enter the name of 1 of the contacts in
lets say G1 and it will search for that name in A1:B73 and automatically copy
its colour code over.
Many thanks for any help.
Al
 
M

Mike H

Hi,

I'm assuming that the colour codeing isn't a result of conditional
formatting and it's simply a fill colour. To do this you need VB.

Alt+F11 to open vb editor. Double click the worksheet that this data are on
and paste the code in on the right. Close VB editor and type your name in G1
and your away.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
If Target.Address = "$G$1" Then
Application.EnableEvents = False
On Error GoTo GetMeOut
Set rfound = Range("A1:B73").Find(What:=Target.Value,
After:=Cells(1, 1), _
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
Target.Interior.ColorIndex = rfound.Interior.ColorIndex
Application.EnableEvents = True
End If
Exit Sub
GetMeOut:
MsgBox "Lookup no found"
Target.Interior.ColorIndex = xlNone
Application.EnableEvents = True
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.
 
G

gramps

Thanks Mike that's bang on the money!!Al

Mike H said:
Hi,

I'm assuming that the colour codeing isn't a result of conditional
formatting and it's simply a fill colour. To do this you need VB.

Alt+F11 to open vb editor. Double click the worksheet that this data are on
and paste the code in on the right. Close VB editor and type your name in G1
and your away.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
If Target.Address = "$G$1" Then
Application.EnableEvents = False
On Error GoTo GetMeOut
Set rfound = Range("A1:B73").Find(What:=Target.Value,
After:=Cells(1, 1), _
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
Target.Interior.ColorIndex = rfound.Interior.ColorIndex
Application.EnableEvents = True
End If
Exit Sub
GetMeOut:
MsgBox "Lookup no found"
Target.Interior.ColorIndex = xlNone
Application.EnableEvents = True
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.
 
M

Mike H

Glad I could help and thanks for the feedback
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.
 

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