Results 1 to 5 of 5

Apply background colour and font colour on sheets following specific naming pattern

Threaded View

  1. #1
    Forum Contributor
    Join Date
    02-07-2013
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    105

    Apply background colour and font colour on sheets following specific naming pattern

    Hello everyone,

    I have put together the below code:
      Private Sub Worksheet_SelectionChange(ByVal Target As Range)
         Dim i As Long, r1 As Range, r2 As Range
    
       For i = 6 To 300
          Set r1 = Range("b" & i)
          Set r2 = Range("b" & i & ":b" & i)
          Set r3 = Range("i" & i)
          Set r4 = Range("l" & i)
          Set r5 = Range("o" & i)
        
        If r1.Value = Sheet1.Range("D8") Then r2.Interior.Color = RGB(255, 51, 0)
        If r1.Value = Sheet1.Range("D7") Then r2.Interior.Color = RGB(255, 192, 0)
        If r1.Value = Sheet1.Range("D6") Then r2.Interior.Color = RGB(255, 255, 0)
        If r1.Value = Sheet1.Range("D5") Then r2.Interior.Color = RGB(146, 208, 80)
        If r1.Value = Sheet1.Range("D4") Then r2.Interior.Color = RGB(51, 204, 255)
        If r1.Value = Sheet1.Range("D3") Then r2.Interior.Color = RGB(255, 153, 204)
        If r1.Value = "" Then r2.Interior.Color = RGB(255, 255, 255)
          
        If r3.Value = Sheet1.Range("f3") Then r3.Interior.Color = RGB(204, 255, 51)
        If r3.Value = Sheet1.Range("f4") Then r3.Interior.Color = RGB(244, 136, 162)
        If r3.Value = Sheet1.Range("f5") Then r3.Interior.Color = RGB(255, 210, 17)
        If r3.Value = Sheet1.Range("f6") Then r3.Interior.Color = RGB(186, 225, 143)
        If r3.Value = Sheet1.Range("f7") Then r3.Interior.Color = RGB(245, 232, 216)
        If r3.Value = Sheet1.Range("f8") Then r3.Interior.Color = RGB(245, 232, 216)
        If r3.Value = "" Then r3.Interior.Color = RGB(255, 255, 255)
    
        If r4.Value = Sheet1.Range("f3") Then r4.Interior.Color = RGB(204, 255, 51)
        If r4.Value = Sheet1.Range("f4") Then r4.Interior.Color = RGB(244, 136, 162)
        If r4.Value = Sheet1.Range("f5") Then r4.Interior.Color = RGB(255, 210, 17)
        If r4.Value = Sheet1.Range("f6") Then r4.Interior.Color = RGB(186, 225, 143)
        If r4.Value = Sheet1.Range("f7") Then r4.Interior.Color = RGB(245, 232, 216)
        If r4.Value = Sheet1.Range("f8") Then r4.Interior.Color = RGB(245, 232, 216)
        If r4.Value = "" Then r4.Interior.Color = RGB(255, 255, 255)
    
    
        If r5.Value = Sheet1.Range("f3") Then r5.Interior.Color = RGB(204, 255, 51)
        If r5.Value = Sheet1.Range("f4") Then r5.Interior.Color = RGB(244, 136, 162)
        If r5.Value = Sheet1.Range("f5") Then r5.Interior.Color = RGB(255, 210, 17)
        If r5.Value = Sheet1.Range("f6") Then r5.Interior.Color = RGB(186, 225, 143)
        If r5.Value = Sheet1.Range("f7") Then r5.Interior.Color = RGB(245, 232, 216)
        If r5.Value = Sheet1.Range("f8") Then r5.Interior.Color = RGB(245, 232, 216)
        If r5.Value = "" Then r5.Interior.Color = RGB(255, 255, 255)
        
        
       Next i
    End Sub
    I would like it to be applied only to sheets named in "DD.MM" format

    At the moment it works but because i pasted the code on each sheet; i want it to be in a module only.
    I would also like the text in "I6:i90","l6:l90","o6:o90" to be white. (girly stuff, looks nicer )


    can you please help?


    thank you in advance
    Last edited by annazet; 09-14-2018 at 08:39 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] format a cell background colour based on a manual background colour of an adjacent cell
    By Nampara in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-24-2018, 04:03 PM
  2. [SOLVED] Search cells based on student name, cell background colour and return a tally for colour
    By drof_06 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-26-2016, 04:31 AM
  3. Replies: 6
    Last Post: 03-12-2014, 09:52 AM
  4. [SOLVED] change of font colour or background colour vba
    By KK1234 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-22-2014, 08:20 PM
  5. Extract Cell Font/Background Colour
    By icu222much in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 07-02-2010, 11:17 PM
  6. Worksheet Background and Font Colour
    By Apple Ling in forum Excel General
    Replies: 9
    Last Post: 06-23-2009, 03:10 AM
  7. How can I count cells of a specific colour (pattern)?
    By Nick@Durham in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-29-2005, 06:25 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1