Results 1 to 3 of 3
  1. #1
    Johnny12 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2012
    Posts
    31

    Export to Excel - VBA - Conditional Highlight

    Hey everyone! This should be rather simple, but my brain just isn't working. I have a table that is exported to Excel via an Event Procedure using VBA. Depending the source data it could have several hundred rows of data. Some of these rows in column R, if the value is greater than 0, I would like the background to be RED. I've tried a few things and they haven't worked. Can I get a little help?

    This is my last attempt.

    Code:
     If .Range("R" & i).Value > 0 Then .Range("R" & i).Interior.ColorIndex = 3


  2. #2
    Johnny12 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2012
    Posts
    31
    So, after I posted the above I read one of my older posts. in that post, @pdaldy mentioned using recoding a macro in Excel and bringing it into the VBA. It worked! Thanks again. That is an amazing trick.

    The only remaining question, the below code also turns the header (R1) red. Don't want that. ??


    Code:
       Columns("R:R").Select    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
            Formula1:="=0"
        Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
        With Selection.FormatConditions(1).Font
            .Color = -16383844
            .TintAndShade = 0
        End With
        With Selection.FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .Color = 13551615
            .TintAndShade = 0
        End With
        Selection.FormatConditions(1).StopIfTrue = False

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Ha! I was just about to post it again. I'm lazy, so getting Excel to show me the code is my default.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 10-18-2019, 06:09 AM
  2. Replies: 3
    Last Post: 04-07-2016, 04:36 AM
  3. Export query to Excel and apply conditional formatting
    By mcpearce in forum Import/Export Data
    Replies: 4
    Last Post: 04-27-2014, 05:26 PM
  4. Replies: 3
    Last Post: 10-07-2011, 07:49 AM
  5. Replies: 3
    Last Post: 01-17-2011, 08:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums