+ Reply to Thread
Results 1 to 4 of 4

Subtracing fill color cells and displaying them somewhere

Hybrid View

  1. #1
    Registered User
    Join Date
    02-22-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    2

    Subtracing fill color cells and displaying them somewhere

    VBA programming noob here...
    I would like to do a simple task where a macro can find a cell that's colored yellow, use the value that is in it and subtract it from a cell that's colored green. That value should also be displayed on a cell different from those 2 cells.

    The x.Interior.ColorIndex for the green highlight is 43 and yellow is 6

    Keeping it simple, I only have 1 cell highlighted with each of the colors... not sure if it matters or not

    Thanks in advance

  2. #2
    Forum Contributor
    Join Date
    02-04-2010
    Location
    Hertfordshire, England
    MS-Off Ver
    Office 2007 (home) Office 365 (work)
    Posts
    134

    Re: Subtracing fill color cells and displaying them somewhere

    Hi

    The following code assigns the value of the highlighted cells to variables which enables you to perform your calculation.

    Sub CalculationBasedOnFormat()
        Dim xCell As Range
        For Each xCell In ActiveSheet.UsedRange
            If xCell.Interior.ColorIndex = 43 Then
                ZgrVal = xCell.Value
            ElseIf xCell.Interior.ColorIndex = 6 Then
                ZyellVal = xCell.Value
            End If
        Next xCell
        Diff = ZgrVal - ZyellVal    'put this value wherever you need it
        MsgBox Diff
    End Sub
    please amend accordingly.

  3. #3
    Registered User
    Join Date
    02-22-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Subtracing fill color cells and displaying them somewhere

    Perfect. Thank you so much!

  4. #4
    Forum Contributor
    Join Date
    02-04-2010
    Location
    Hertfordshire, England
    MS-Off Ver
    Office 2007 (home) Office 365 (work)
    Posts
    134

    Re: Subtracing fill color cells and displaying them somewhere

    Hi psxsquall

    You are welcome.

    Please can you change the thread to solved and provide feedback by clicking on the feedback scales.

    Thanks

+ 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