welshgasman
Well-known Member
- Joined
- May 25, 2013
- Messages
- 1,402
- Office Version
- 2019
- 2007
- Platform
- Windows
Hi all,
The Community Car Scheme I volunteer for is wishing to print out the data from their spreadsheet, but want to keep the colour coded data.
I have found out how to colour code in mailmerge at Mailmerge Tips & Tricks
For that I thought of having a column for each actual colum that needs to be colour coded. Fortunately we are not talking about too many columns at the moment.
So if column A for a row needs to be Red, then the word Red is in column K.
So instead of the user actually colour coding the data, they just enter Red, Blue or Yellow in their respective columns and I write a little sub to set those colours (colourCode)
The benefit then is that I can test those extra columns in Mailmerge and set as needed.
So I have created two functions at present.
One is to set those columns where I can as the sheet will be quite long. The other is to get the colour of column A into column O. SO column K will set the colour of column A and column O will read that colour and display the colour word, hopefully the same as column K.?
Then when the 'colour' columns are correct, they can just set the colours via the colour columns, and run ColorCode.
However when the colour is Black, despite correctly identifying that colour, the relevent cell in column O is not set?, remains blank. I cannot find out why.
Not is mght be better to leave those empty so as to be able to see the wood for the trees, but I would like to find out why Black is not displayed?
Just working on one column pair for now, until I get it working as I would like.
TIA
Edit: Marvellous, as soon as I upload here I get it working , however if anyone has a better method, I would love to hear it.
The Community Car Scheme I volunteer for is wishing to print out the data from their spreadsheet, but want to keep the colour coded data.
I have found out how to colour code in mailmerge at Mailmerge Tips & Tricks
For that I thought of having a column for each actual colum that needs to be colour coded. Fortunately we are not talking about too many columns at the moment.
So if column A for a row needs to be Red, then the word Red is in column K.
So instead of the user actually colour coding the data, they just enter Red, Blue or Yellow in their respective columns and I write a little sub to set those colours (colourCode)
The benefit then is that I can test those extra columns in Mailmerge and set as needed.
So I have created two functions at present.
One is to set those columns where I can as the sheet will be quite long. The other is to get the colour of column A into column O. SO column K will set the colour of column A and column O will read that colour and display the colour word, hopefully the same as column K.?
Then when the 'colour' columns are correct, they can just set the colours via the colour columns, and run ColorCode.
However when the colour is Black, despite correctly identifying that colour, the relevent cell in column O is not set?, remains blank. I cannot find out why.
Not is mght be better to leave those empty so as to be able to see the wood for the trees, but I would like to find out why Black is not displayed?
Just working on one column pair for now, until I get it working as I would like.
TIA
Address trial.xlsm | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | |||
1 | Surname | Title | DataP | Address 1 | Address 2 | Tel 1 | Tel 2 | Ice | Notes | ColSurname | ColDataP | ||||||
2 | Alcock | Mrs | 01/01/21 | 44 Einon Court | Gorseinon | 01792 565656 | 07891 654565 | Gina 565656 | Yellow | Yellow | |||||||
3 | Able | Mr & Mrs | 01/12/22 | 12 High Road | G/ Village | 01792 565656 | 07891 654565 | ||||||||||
4 | Ace | Mr & Mrs | 30 Low Road | Gorseinon | 01792 565656 | 07891 654565 | Scooter | Green | Green | ||||||||
5 | Ackroyd | Mrs | 01/02/21 | 7 Heol Nant | Gorseinon | 01792 565656 | 07891 654565Dau 548598 | Blue | Blue | ||||||||
6 | Bateman | Mr & Mrs | 64 Bryngwastad | Gorseinon | 01792 565656 | Blind | |||||||||||
7 | Best | Mrs | 01/12/19 | 22 Bryngwastad | Gorseinon | 07891 654565 | |||||||||||
8 | Blessed | Mrs | 28 Highfield | Loughor | 01792 565656 | High Vehicle | Red | Red | |||||||||
9 | Brain | Mr | 01/06/18 | 6 High Street | Grovesend | 01792 565656 | Dau 548598 | Folding Wheelchair | |||||||||
Sheet1 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
O2:O9,K6:K9,K2:K3 | K2 | =showcolour("A" & ROW()) |
Code:
Option Explicit
Function ShowColour(RngCell As String) As String
Dim strColour As String
Dim iColour As Integer
iColour = Range(RngCell).Font.ColorIndex
'Debug.Print Range(RngCell).Font.Color
Select Case iColour
Case 6
strColour = "Yellow"
Case 5
strColour = "Blue"
Case 4
strColour = "Green"
Case 3
strColour = "Red"
Case Else
strColour = "Black"
End Select
ShowColour = strColour
End Function
Function GetColour(strColour As String) As Integer
Dim iColour As Integer
Select Case strColour
Case "Yellow"
iColour = 6
Case "Blue"
iColour = 5
Case "Green"
iColour = 4
Case "Red"
iColour = 3
Case Else
iColour = 1
End Select
GetColour = iColour
End Function
Option Explicit
Sub ColourCode()
Dim iLastRow As Integer, iRow As Integer, iColour As Integer
iLastRow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row
For iRow = 2 To iLastRow
' Surname first
iColour = GetColour(Range("A" & iRow).Offset(0, 10).Value)
If Range("A" & iRow).Font.ColorIndex <> iColour Then
Range("A" & iRow).Font.ColorIndex = iColour
End If
Next
End Sub
Edit: Marvellous, as soon as I upload here I get it working , however if anyone has a better method, I would love to hear it.