Consulting

Results 1 to 9 of 9

Thread: Highlighting cells using VBA & Sumif()

  1. #1
    VBAX Regular xls's Avatar
    Joined
    Aug 2005
    Posts
    76
    Location

    Highlighting cells using VBA & Sumif()

    Find attached file. I have manually highlighted cells which qualifies criterion mentioned using sumif(). Color of the highlighted cells is as same as cells qualified usinf sumif().Is it possible to do using VBA or in any other way.
    Winners dont do different things, they do things differently.

  2. #2
    Hi

    This has hardcoded ranges but it should get you going.

    [VBA]
    Sub ccc()
    Dim nodupes As New Collection
    For Each ce In Range("E80:E88")
    nodupes.Add Item:=ce.Offset(0, -1).Interior.ColorIndex, key:=Format(ce.Value, "mmm")
    Next ce

    For Each ce In Range("C4:C76")
    ce.Interior.ColorIndex = nodupes(Format(ce.Offset(0, -2), "mmm"))
    ce.Offset(0, 1).Interior.ColorIndex = nodupes(Format(ce.Offset(0, -2), "mmm"))
    Next ce

    End Sub

    [/VBA]


    Tony

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    What exactly are you wanting? Do you want the code to setup the colours, to calculate the totals nit using SUMIF, or what?

  4. #4
    VBAX Regular xls's Avatar
    Joined
    Aug 2005
    Posts
    76
    Location
    Quote Originally Posted by xld
    What exactly are you wanting? Do you want the code to setup the colours, to calculate the totals nit using SUMIF, or what?
    Below there is formula using sum if. I want databse to highlighted according to formulae mentioned.

    E.g. In cell sum if is giving data for the period between 01/04/06 and 01/03/06, and highlighted with say yellow color. I want the qualified data as per sum if above also to be highlighted in yellow color.
    Winners dont do different things, they do things differently.

  5. #5
    VBAX Regular xls's Avatar
    Joined
    Aug 2005
    Posts
    76
    Location
    [/vba]

    Tony[/quote]

    Can u tell me how it works.
    Winners dont do different things, they do things differently.

  6. #6
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    You can use a 'select case' for the months so from 1 to 12 and color the row accordingly with the targetcolumn.[VBA]Private Sub Worksheet_Change(ByVal Target As Range)
    Dim vmonth As String
    If Target.Column = 1 Then
    vmonth = CStr(Month(Target.Value))
    Select Case vmonth
    Case "1"
    'yellow
    Range("A" & Target.Row & "" & Target.Row).Interior.ColorIndex = 6
    Case "2"
    'red
    Range("A" & Target.Row & "" & Target.Row).Interior.ColorIndex = 3
    End Select
    End If
    End Sub[/VBA]

  7. #7
    xls

    Not sure of the intent of your question. Do you want a breakdown on the logic of the code, or do you want to know how to make the code run and action the data...


    Tony

  8. #8
    VBAX Regular xls's Avatar
    Joined
    Aug 2005
    Posts
    76
    Location
    Quote Originally Posted by acw
    xls

    Not sure of the intent of your question. Do you want a breakdown on the logic of the code, or do you want to know how to make the code run and action the data...


    Tony
    I want to know how to make the code run and action the data.
    Winners dont do different things, they do things differently.

  9. #9
    Hi

    While in your spreadsheet, press ALT F11. This will open the Visual Basic Editor. Go Insert, Module. Copy the code from the board and paste it into this module.

    Go back to the spreadsheet, make sure you are on the relevant sheet, press F8, select the macro that you have just inserted, then run.


    Tony

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •