+ Reply to Thread
Results 1 to 9 of 9

How to create macro/vba to highlight or conditional formating to a group of cells.

Hybrid View

  1. #1
    Registered User
    Join Date
    06-30-2010
    Location
    Newport New VA
    MS-Off Ver
    Excel 2003
    Posts
    97

    How to create macro/vba to highlight or conditional formating to a group of cells.

    I need a macro/code to highlight a select set of cell/rows with the color blue.

    The rows with have a 1 in column A.. All row with 1 need to be highlighted blue.

    Thank you in advance for your help..

  2. #2
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: How to create macro/vba to highlight or conditional formating to a group of cells.

    not sure if this is the same/close to the other post....but here goes...this does a little more than this thread asks for....

    Sub testing()
    
        Dim LastRow As Single, LastRowOnes As Single, x As Single
        
        LastRow = Cells(65000, 1).End(xlUp).Row
        
        For x = 1 To LastRow
            If Cells(x, 1).Value = 0 Then
                LastRowOnes = x - 1
                Exit For
            End If
        Next x
        
        Rows("1:" & LastRowOnes).Select
        With Selection.Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .Color = 15773696
            .TintAndShade = 0
            .PatternTintAndShade = 0
        End With
        
        Rows(LastRowOnes + 1 & ":" & LastRowOnes + 1).Select
        Selection.Insert Shift:=xlDown
        Selection.Insert Shift:=xlDown
        Selection.Insert Shift:=xlDown
        Selection.Insert Shift:=xlDown
        Selection.Insert Shift:=xlDown
        Rows(LastRowOnes + 1 & ":" & LastRowOnes + 5).Select
        With Selection.Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .ThemeColor = xlThemeColorDark1
            .TintAndShade = 0
            .PatternTintAndShade = 0
        End With
        Cells(1, 1).Select
    
    End Sub
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

  3. #3
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: How to create macro/vba to highlight or conditional formating to a group of cells.

    You could use a conditional format
    Select B2
    Select --> Home > Conditional Formating > Manage Rules >New Rule >Use a formula to determine which cells to format
    Format values where this formula is true --> =$A2 = 1
    Format --> Select fill = blue
    Copy B2 and do a "Paste Special"> Formats" in all cells in all rows and coluns
    Last edited by PCI; 11-13-2013 at 05:26 PM.

  4. #4
    Registered User
    Join Date
    06-30-2010
    Location
    Newport New VA
    MS-Off Ver
    Excel 2003
    Posts
    97

    Re: How to create macro/vba to highlight or conditional formating to a group of cells.

    I am getting a run time error 13 ?type Mismatch... when i run debug the following is highlighted in yellow

    Rows("1:" & LastRowOnes).Select

  5. #5
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: How to create macro/vba to highlight or conditional formating to a group of cells.

    If you really need a macro perhaps try
    Option Explicit
    
    Sub ColorRow()
    Dim F  As Range
        For Each F In Range([A1], Range("A" & Rows.Count).End(xlUp))
            If (F.Value = 1) Then F.EntireRow.Interior.Color = 15773696
        Next
    End Sub

  6. #6
    Registered User
    Join Date
    06-30-2010
    Location
    Newport New VA
    MS-Off Ver
    Excel 2003
    Posts
    97

    Re: How to create macro/vba to highlight or conditional formating to a group of cells.

    PCI.. im not sure how to apply the macro you just wrote above. i copy pasted it into a module in VBAProject(personal.xls8) and then click run to run it..but nothing happened... ..

  7. #7
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: How to create macro/vba to highlight or conditional formating to a group of cells.

    The macro is working in the active sheet
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    06-30-2010
    Location
    Newport New VA
    MS-Off Ver
    Excel 2003
    Posts
    97

    Re: How to create macro/vba to highlight or conditional formating to a group of cells.

    Ok it worked on the active sheet. but that wud mean that no one else could use it..correct.... how do i share it and use it on other worksheets..with out having to copy and paste it into vba of each worksheet...

  9. #9
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: How to create macro/vba to highlight or conditional formating to a group of cells.

    You just need to select a sheet to treat and launch the macro
    In the file attached you can use a short cut to launch it: CONTROL + g
    Attached Files Attached Files

+ 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. [SOLVED] Highlight Cells using Conditional Formating
    By dompoma in forum Excel General
    Replies: 4
    Last Post: 04-05-2013, 05:44 PM
  2. Macro of conditional formating, Highlight all duplicates + its unique
    By rain4u in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-11-2011, 05:29 AM
  3. Conditional formating highlight cells in column Q that have certain word in it
    By rain4u in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-30-2011, 02:26 PM
  4. Replies: 3
    Last Post: 08-28-2009, 11:16 AM
  5. Replies: 1
    Last Post: 10-25-2007, 04:09 PM

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