+ Reply to Thread
Results 1 to 8 of 8

Highlight cell with Fill & Font Colour

Hybrid View

  1. #1
    Registered User
    Join Date
    04-06-2016
    Location
    malaysia
    MS-Off Ver
    MS office 2013
    Posts
    12

    Unhappy Highlight cell with Fill & Font Colour

    Hi,

    I am working out on the IF & ELSE project. The codes created below are correct but I am not sure how to adjust the Font.

    Basically i need the result of "Insufficient" to be filled with a colour on its Cell.
    Fill Colour: Red
    Font Colour Yellow & also Bold

    Please assist.
    Below are the codings:


    lastrow = Sheets("PO Summary").Cells(Rows.Count, 2).End(xlUp).Row
        erow = 4
        
    For x = 4 To lastrow
      
     Worksheets("PO Summary").Cells(x, 9).FormulaR1C1 = "=(RC6 - RC7)/RC6"
     
         If Worksheets("PO Summary").Cells(x, 7) <= 0 Then
            Worksheets("PO Summary").Cells(x, 8) = "Insufficient"
       
        Else
            Worksheets("PO Summary").Cells(x, 8) = "Sufficient"
     
        End If
    
    erow = erow + 1
    
    Next x
    
    End Sub
    Last edited by FDibbins; 04-25-2016 at 10:14 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: Highlight cell with Fill & Font Colour

    Try inserting above the line starting with "Else.."
    With .Worksheets("PO Summary").Cells(x, 8)
        .Interior.ColorIndex = 3 'red
        .Font.ColorIndex = 6 'yellow
        .Font.Bold = True
    End With
    If a response has helped then please consider rating it by clicking on *Add Reputation below the post
    When your issue has been resolved don't forget to mark the thread SOLVED (click Thread Tools at top of thread)

  3. #3
    Registered User
    Join Date
    04-06-2016
    Location
    malaysia
    MS-Off Ver
    MS office 2013
    Posts
    12

    Re: Highlight cell with Fill & Font Colour

    Quote Originally Posted by Kevin# View Post
    Try inserting above the line starting with "Else.."
    With .Worksheets("PO Summary").Cells(x, 8)
        .Interior.ColorIndex = 3 'red
        .Font.ColorIndex = 6 'yellow
        .Font.Bold = True
    End With
    Hi,

    I have tried to copy but error occurred. It highlights at the word .worksheet
    The error appeared as "invalid/unqualified reference"

  4. #4
    Registered User
    Join Date
    04-06-2016
    Location
    malaysia
    MS-Off Ver
    MS office 2013
    Posts
    12

    Re: Highlight cell with Fill & Font Colour

    Hi Kevin,

    I did try n error and i have found the solution and yes it works!

    I am a beginner, i'd like to add the color coding for "Sufficient" Result.
    May i know what is the coding for Font color white? and font not bold?

    Kindly assist.

    Thanks.

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,333

    Re: Highlight cell with Fill & Font Colour

    Complete stuff.
    Sub tst()
    With Sheets("PO Summary")
        lastrow = .Cells(Rows.Count, 2).End(xlUp).Row
        erow = 4
        For x = erow To lastrow
            .Cells(x, 9).FormulaR1C1 = "=(RC6 - RC7)/RC6"
            If .Cells(x, 7) <= 0 Then
                With .Cells(x, 8)
                    .Value = "Insufficient"
                    .Interior.Color = vbRed
                    .Font.ColorIndex = 6
                    .Font.FontStyle = "Bold"
                End With
            Else
                .Cells(x, 8) = "Sufficient"
            End If
            erow = erow + 1
        Next x
    End With
    End Sub

  6. #6
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: Highlight cell with Fill & Font Colour

    nuraisyah Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (I will add them for you - this time )
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Highlight cell with Fill & Font Colour

    nuraisyah,

    Do you need to loop?
    No loop and conditional format.
    Sub tst()
        Dim lastrow As Long, erow As Long
        With Sheets("PO Summary")
            lastrow = .Cells(Rows.Count, 2).End(xlUp).Row
            erow = 4
            With .Range("h" & erow & ":h" & lastrow)
                .FormatConditions.Delete
                .Offset(, 1).Formula = "=(f" & erow & "-g" & erow & ")/f" & erow
                .Formula = "=if(g4<=0,""Insufficient"",""Sufficient"")"
                .FormatConditions.Add Type:=xlExpression, Formula1:="=h" & erow & "=""Insufficient"""
                .FormatConditions(1).Font.Bold = True
                .FormatConditions(1).Font.Color = vbYellow
                .FormatConditions(1).Interior.Color = vbRed
            End With
        End With
    End Sub
    Last edited by jindon; 04-27-2016 at 12:14 AM.

  8. #8
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: Highlight cell with Fill & Font Colour

    In response to post#6
    "and font not bold?"
    ActiveCell.Font.Bold = False

    "what is the coding for Font color white? "
    -3 different ways to get a white font

    Sub WhiteA()
    ActiveCell.Font.ColorIndex = 2
    End Sub
    OR
    Sub WhiteB()
    ActiveCell.Font.Color = vbWhite
    End Sub
    OR
    Sub WhiteC()
    ActiveCell.Font.Color = RGB(255, 255, 255)
    End Sub
    This link will help you with colours
    Last edited by Kevin#; 04-27-2016 at 12:23 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Font/Cell fill colour issues
    By eBopBob in forum Excel General
    Replies: 1
    Last Post: 03-30-2014, 10:21 AM
  2. Replies: 1
    Last Post: 09-12-2013, 02:09 PM
  3. Copy font/colour/fill of cells from one sheet into another.
    By stacesil in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-18-2013, 07:59 PM
  4. Replies: 6
    Last Post: 03-22-2012, 06:29 AM
  5. Command Buttons for Fill Colour and Font Colour
    By Gos-C in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 07-14-2011, 07:11 AM
  6. Multiple Fill Color & Font Colour icons on menu bar
    By robertguy in forum Excel General
    Replies: 3
    Last Post: 02-05-2008, 10:46 AM
  7. Criteria - Automatic Change Font or Fill Colour
    By stevembe in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-04-2005, 12:05 AM

Tags for this Thread

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