+ Reply to Thread
Results 1 to 4 of 4

Sumif - Colorindex = 37

Hybrid View

  1. #1
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,879

    Sumif - Colorindex = 37

    I have some data where I have colored certain Values.

    I want to write a code that would Sum only if the Color Index is 37.

    I have attached the sheet as well as the code.

    Can anyone clarify what is wrong?

    Code =


    Sub Colorindex()
    
    
    Dim LR As Integer, Counter As Byte, GT As Double
    
    ThisWorkbook.Sheets("Sheet1").Activate
    
    LR = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
    
    For Counter = 1 To LR
     
    GT = Application.WorksheetFunction.SumIf(Range("A1:A" & LR), Range("A" & Counter).Interior.Colorindex = 37, (Range("A1:A" & LR)))
    
    
    Next Counter
    
    End Sub
    Attached Files Attached Files
    Cheers!
    Deep Dave

  2. #2
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Sumif - Colorindex = 37

    Hi,

    I have changed your code as follows :

    Sub Colorindex()
    
    
    Dim LR As Integer, Counter As Byte, GT As Double
    
    ThisWorkbook.Sheets("Sheet1").Activate
    
    LR = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
    
    For Counter = 1 To LR
    
     If Sheets("Sheet1").Cells(Counter, 1).Interior.Colorindex = 37 Then
     GT = GT + Sheets("Sheet1").Cells(Counter, 1)
     End If
     
    'GT = Application.WorksheetFunction.SumIf(Range("A1:A" & LR), Range("A" & Counter).Interior.Colorindex = 37, (Range("A1:A" & LR)))
    
    
    
    Next Counter
    MsgBox GT
    End Sub
    Happy Computing ,

    Xlbiznes.

    To show your appreciation please click *

  3. #3
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,879

    Re: Sumif - Colorindex = 37

    Works!! Thank you..

  4. #4
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Sumif - Colorindex = 37

    Glad i could help,

    Please mark this thread as solved if you are satisfied with the solution provided.

+ 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