Hi,
I've been trying to shade a cell (A2) a certain color based on the value in another cell (B2), but I can't seem to get there with the code I've pieced together from other code snippets.
I have a table of cities ("contacts200805_table") where the city cells are color coded based on which person is assigned to work in that city. People are often reassigned to different cities, so I'm trying to create a macro that will update the cell color for me.
I use a different software to generate the list of people and their assigned cities. I copy the list into a table ("input_contacts"). The city info populates A2:A1043. The person's name populates B2:B1043. "Input_contacts" and "contacts200805" have the exact same cities and always will. The people will change. I use the "input contacts" table to just dump the new list. The "contacts200805" table is what I use for the report, so the format can't be changed.
Here is what I want my macro to do:
start macro
select the "input contacts" table
copy the people in range B2:B118
select the "contacts200805" table
paste the people in B2:B118 which is next to the city column (A2:A118)
repeat for other columns
look at the name in cell B2 on the "contacts200805" table
if name = jane doe then color the city cell (A2) red
if name= john hanson then color city cell green, etc. (I have 6 people to compare)
repeat check for all cells that contain a persons name (columns B, D, F, H, J, L, N, P & R)
make the person's name text color white so it doesn't show up on the final printout
end macro
When I run the macro below I get a 'type mismatch' error at the first case select
Sub Contacts_Click()
'select the input_contacts sheet and select the a set of contacts and copy
'go to contacts200805 table and paste the contacts into the column next to the city column
Sheets("input_contacts").Select
Range("B2:B118").Select
Selection.Copy
Sheets("contacts200805_table").Select
Range("B2:B118").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Sheets("input_contacts").Select
Range("B119:B235").Select
Selection.Copy
Sheets("contacts200805_table").Select
Range("D2:D118").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Sheets("input_contacts").Select
Range("B236:B352").Select
Selection.Copy
Sheets("contacts200805_table").Select
Range("F2:F118").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Sheets("input_contacts").Select
Range("B353:B469").Select
Selection.Copy
Sheets("contacts200805_table").Select
Range("H2:H118").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Sheets("input_contacts").Select
Range("B470:B586").Select
Selection.Copy
Sheets("contacts200805_table").Select
Range("J2:J118").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Sheets("input_contacts").Select
Range("B587:B703").Select
Selection.Copy
Sheets("contacts200805_table").Select
Range("L2:L118").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Sheets("input_contacts").Select
Range("B704:B820").Select
Selection.Copy
Sheets("contacts200805_table").Select
Range("N2:N118").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Sheets("input_contacts").Select
Range("B821:B937").Select
Selection.Copy
Sheets("contacts200805_table").Select
Range("P2:P118").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Sheets("input_contacts").Select
Range("B938:B1043").Select
Selection.Copy
Sheets("contacts200805_table").Select
Range("R2:R107").Select
ActiveSheet.Paste
Application.CutCopyMode = False
'conditional formatting
'look at the contact names in columns B, D, F, H, J, L, N, P, R and if they match any
'of the case values then color the city’s cell to the left of the name a certain color
'brown=53
'tan=40
'sea green=50
'pink=7
'gold=44
'rose=38
'light yellow=36
Select Case Range("B2:B118").Value
Case "Jane Doe"
Range("B2").Offset(0, -1).Interior.ColorIndex = 7
Case "John Hanson"
Range("B2").Offset(0, -1).Interior.ColorIndex = 44
Case "Charlie Boone"
Range("B2").Offset(0, -1).Interior.ColorIndex = 38
Case "Jack Grough"
Range("B2").Offset(0, -1).Interior.ColorIndex = 36
Case "Linda May"
Range("B2").Offset(0, -1).Interior.ColorIndex = 53
Case "Dan Bee"
Range("B2").Offset(0, -1).Interior.ColorIndex = 40
Case "Dave Gill"
Range("B2").Offset(0, -1).Interior.ColorIndex = 50
Case Else
Range("B2").Offset(0, -1).Interior.ColorIndex = 255
End Select
'make the text in the columns between the city columns white
Range("B2:B118").Select
Selection.Font.ColorIndex = 2
Range("D2:D118").Select
Selection.Font.ColorIndex = 2
Range("F2:F118").Select
Selection.Font.ColorIndex = 2
Range("H2:H118").Select
Selection.Font.ColorIndex = 2
Range("J2:J118").Select
Selection.Font.ColorIndex = 2
Range("L2:L118").Select
Selection.Font.ColorIndex = 2
Range("N2:N118").Select
Selection.Font.ColorIndex = 2
Range("P2:P118").Select
Selection.Font.ColorIndex = 2
Range("R2:R118").Select
Selection.Font.ColorIndex = 2
End Sub
Display More
I've also attached sample xls file. The colors and names may not match up correctly because I changed the names for the sample.
Any suggestions is greatly appreaciated,
Charlotte