+ Reply to Thread
Results 1 to 4 of 4

Thread: Highlight Certain Data Using Macros

  1. #1
    Registered User
    Join Date
    08-17-2010
    Location
    Leeds
    MS-Off Ver
    Excel 2003
    Posts
    2

    Question Highlight Certain Data Using Macros

    Hi,

    I am an absolute novice with macros in Excel so was wondering if someone could help me.

    Basically we have a set of data that we pull each month which is essentially a long list of numbers. Contained within the same cell as the numbers is a + or - plus a number of how much the figure has increased or decreased since the last month. For example:

    56(+4)
    76(-2)
    102(-7)
    36(+50)

    I want to be able to highlight the numbers that are + in green and - in red. I can't seem to find a way to do this, if anyone could help I'd be very grateful!

    Thanks

  2. #2
    Forum Guru Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007
    Posts
    3,523

    Re: Problem Highlighting Certain Data Using Marcos

    Adjust range reference to suit.

    Option Explicit
    
    Sub Highlight()
    
        Dim c As Range, lrow As Long, p1, p2
        
        lrow = Cells(Rows.Count, "A").End(xlUp).Row
        
        Application.ScreenUpdating = False
        
        On Error Resume Next
        For Each c In Range("A1:A" & lrow)
            p1 = InStr(1, c.Value, "+", vbTextCompare)
            p2 = InStr(1, c.Value, "-", vbTextCompare)
            If p1 > 0 Then c.Interior.ColorIndex = 4 'green
            If p2 > 0 Then c.Interior.ColorIndex = 3 'red
            
        Next c
    
        Application.ScreenUpdating = True
    
    End Sub
    Palmetto

    Do you know . . . ?

    You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.

  3. #3
    Forum Guru Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    Excel 2010
    Posts
    1,249

    Re: Highlight Certain Data Using Macros

    Just use conditional formatting.

    1:Select your range.

    2:Go to "Format" -> "Conditional Formatting"

    3: Select the "Formula" option.

    4: Enter the formula "=ISNUMBER(FIND("+",A1))" (without the quotes and assuming A1 is the active cell).

    5: Select the format you want.

    6: Click "Add >>"

    7: Select the "Formula" option.

    8: Enter the formula "=ISNUMBER(FIND("-",A1))" (without the quotes).

    9: Select the format you want.

    10: Click "Ok".
    Last edited by Whizbang; 08-17-2010 at 02:47 PM.

  4. #4
    Registered User
    Join Date
    08-17-2010
    Location
    Leeds
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Highlight Certain Data Using Macros

    Thanks for this both solutions work fine. You have literally saved me hours!


+ 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.2.0