+ Reply to Thread
Results 1 to 5 of 5

Highlighting Rows Macro

Hybrid View

  1. #1
    Registered User
    Join Date
    05-31-2012
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2003
    Posts
    9

    Highlighting Rows Macro

    I am pretty new to macros. I was wondering if I could create a Macro that reads a column (let's assume F from F4 to F250). In that column it will consistently run so that everytime I put an x in the column (to check it off), it will highlight the next column. I'm always highlighting the rows I am working on and if I could have a macro that automatically does it for me without highlight and then unhilighting and then highliting the next row that would be great.

    Thanks!

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Highlighting Rows Macro

    Hi Shep, welcome to the forum.

    You can do this without a macro by using Conditional Formatting. For example:

    Select G4:G250, then open the Conditional Formatting dialog. Select 'Use a formula to determine...' and then type the following formula in the textbox provided:

    =F4="X"

    Set the fill (highlight) color to yellow or whatever you desire, then click OK twice to return to your sheet. Whenever you enter an x in F4:F250, that row in column G will turn the color you chose.

  3. #3
    Registered User
    Join Date
    05-31-2012
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Highlighting Rows Macro

    I understand that but what I am trying to do is highlight the next row. Say I hax an x in row 5, then row 6 will be highlighted. Then when I put an x in row 6 I want row 6 to no longer be highlighted and then row 7 to highlight. I created the event I just need to fix the actual macro. It is as follows (don't know if the firstAddress part does anything):
    Event:
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("F4:F200")) Is Nothing Then
    Call autoHighlight
    End If
    End Sub
    Macro:
    Sub autoHighlight()
    Dim rg As Range, c As Range
      Dim firstAddress As String
        Set rg = Range("F4", "F250")
        Application.ScreenUpdating = False
    With rg
        Set c = .Find("x", lookat:=xlWhole, LookIn:=xlValues)
        If Not c Is Nothing Then
            firstAddress = c.Address
            Do
                c.EntireRow.Interior.ColorIndex = 6
                Set c = .FindNext(c)
                If c Is Nothing Then Exit Do
            Loop While c.Address <> firstAddress
        End If
    Application.ScreenUpdating = True
    End With
    End Sub
    Last edited by Paul; 05-31-2012 at 04:07 PM. Reason: Added CODE tags for new user. Please do so yourself in the future.

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Highlighting Rows Macro

    Hi Shep123,

    What about:

    Application.ScreenUpdating = False
    in your code?
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  5. #5
    Registered User
    Join Date
    05-31-2012
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Highlighting Rows Macro

    I figured it out.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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