These coloured cells also contain numbers and words. I would like all the cells to have a word added to the end of the cell. It should not replace the existing data in the cell.
For example: Cell C3 is colour "16776960" and contains the text "Commodity Fund". I would like the cell to have the word "(Blue)" added to it. So Cell C3 will contain "Commodity Fund (Blue)"
" (Blue)" for colour 16776960 " (Green)" for colour 52377 " (Pink)" for the colour 13408767 " (Red)" for the colour 255
If possibile I'd like to highlight the range of cells that are coloured and then run the vba code you give me.
I hope I explained this well, if not please do ask me more specific questions. I am using Excel 2010 on Windows 7.
So this is what I've come up with for changing the coloured cells to have the words in them. The problem is that it repalces the data in the cell, when I need it to be added at the end of the cell's contents:
Sub Colours_Selected() ' ' Colours_Selected Macro ' ' Keyboard Shortcut: Ctrl+g ' Dim cell As Range Sheets("Pricing1").Select Range("AM15:BI86").Select Range("AM86").Activate ' For Each cell In Selection If cell.Interior.Color = "255" Then cell.Value = "(Red)" ElseIf cell.Interior.Color = "13408767 " Then cell.Value = "(Pink)" ElseIf cell.Interior.Color = "52377" Then cell.Value = "Green" ElseIf cell.Interior.Color = "16776960" Then End If Next cell ' End Sub
I realise now that I need the "(Green)", "(Blue)", "(Red)", "(Pink)" to be in size 8 Times New Roman font. Because some cell contents are in wingdings font. How can this be specified?
The only remaining problem I have is that the text in the cell "CELL.Value" gets converted to Times New Roman font size 8. I only want the new text (e.g. & "(Red)")to be in Times New Roman font size 8. Many of the cells have specific fonts such as wingdings which I don't want to interfere with them.
Sub Colours_Selected() ' ' Colours_Selected Macro ' ' Keyboard Shortcut: Ctrl+g ' Dim CELL As Range Sheets("ISDA Colour Only").Select Range("G11:DJ11").Select Range("G11").Activate ' For Each CELL In Selection If CELL.Interior.Color = "255" Then CELL.Value = CELL.Value & " (Red)" Call ChangeFont(CELL, 5)
ElseIf CELL.Interior.Color = "16776960" Then CELL.Value = CELL.Value & " (Blue)" Call ChangeFont(CELL, 6) End If
Next CELL ' End Sub
Sub ChangeFont(CELL, LENGTOFWORD) With CELL.Characters(Start:=Len(CELL) - LENGTOFWORD, Length:=LENGTOFWORD).Font .Name = "Times New Roman" .Size = 8 End With End Sub
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.