+ Reply to Thread
Results 1 to 5 of 5

Macro to check row's text colour and if text in below rows matches

Hybrid View

  1. #1
    Registered User
    Join Date
    09-19-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    13

    Macro to check row's text colour and if text in below rows matches

    Hi All,
    I have been running reports in excel for a while now and the only way for me to get the data I need from a big bulk of information is to scroll through it and delete the information I don't need, some of these reports have around 100,000 rows and scrolling through to check it all can take a very long time.
    I wonder if it would be possible to create a macro that will check if the text in a row is coloured black, if it is check if the next row's text matches the black text (but not colour) and if so highlight the matching rows until the number changes.

    If you could have a look at the image I attached, ReportExample.jpg I need a macro to detect the 1-11-318658 is in black and then check the rows below it for matching numbers in red/blue/any other colour and then colour the back ground of the matching cells or highlight them some how.
    Would something like this be possible? My experience in VBA is limited but I can normally get my head around already created macros, but creating one from scratch is currently a little out of my reach and I wasn't sure if this would be something that could even be created.

    Thanks in advance for any help.
    Last edited by Raulus; 10-19-2012 at 11:43 AM.

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Macro to check row's text colour and if text in below rows matches

    Try this.

    Sub Test()
    Dim IsBlack As Boolean
    IsBlack = False
    For N = 2 To Cells(Rows.Count, 1).End(xlUp).Row
        If Cells(N, 1).Font.ColorIndex = 1 Then
            IsBlack = True
            Cells(N, 2) = "X"
        Else
            If IsBlack = True And Cells(N, 1) = Cells(N - 1, 1) Then
                Cells(N, 2) = "X"
            Else
                IsBlack = False
            End If
        End If
    Next N
    End Sub
    Open up the VBA editor by hitting ALT F11

    Insert a new module by hitting Insert - Module

    Paste the macro into the empty sheet

    Hit ALT F11 to get back to the worksheet.

    Run the macro by going to tools-macro in Excel 2003 or the view ribbon in Excel 2007/2010.
    Martin

  3. #3
    Forum Contributor
    Join Date
    10-18-2012
    Location
    Telford, England
    MS-Off Ver
    Excel 2010 (2003)
    Posts
    294

    Re: Macro to check row's text colour and if text in below rows matches

    It helps if you upload a specimen spreadsheet if you want more than advice. It would probably take me longer to type the data than to write the code.
    It certainly looks straightforward.

    Let's see if I understand the process. You have a series of rows where the value may repeat non or more times. The first of each group is black, the others may be other colours. You wish to group by highlighting all that share the common value. One would have to not highlight the black line or groups would be indidsitinguishable.

    I'll write the code if you'll confimr/correct and provide the sample data.

  4. #4
    Forum Contributor
    Join Date
    10-18-2012
    Location
    Telford, England
    MS-Off Ver
    Excel 2010 (2003)
    Posts
    294

    Re: Macro to check row's text colour and if text in below rows matches

    Too late! I was interupted while replying and Martin beat me to it. Ho hum

  5. #5
    Registered User
    Join Date
    09-19-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Macro to check row's text colour and if text in below rows matches

    Thank you so much for your help mrice, that worked perfectly!
    Thank you too brynbaker, for replying.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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