Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7631231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:18:09+00:00 2026-05-31T06:18:09+00:00

I will do what I can to make this short and sweet. I have

  • 0

I will do what I can to make this short and sweet. I have an excel Work sheet that needs to sum cells until it reaches the target. Then those cells need an interior color set. The calculations then reset then continue down the range until the next run of cells equals target. The interior should the set to a different color for this set. This would alternate through the range. I have it about 90 % but the second color only highlights for the start of the set and then continues with the first color. Thank you in advance for any pointers

I have :

Sub calctarget()
    Dim x As Variant
    Dim xsub As Variant
    Dim total  As Double
    Dim y As Variant
    Dim target As Double
    Dim RunTotal As Double

    target = 44500

    If RunTotal < target Then y = 0
    RunTotal = 0
    For Each y In Range("a1:a15")
        On Error Resume Next
        RunTotal = RunTotal + y.Value
        If RunTotal < target Then
            y.Interior.ColorIndex = 4
        End If
        If RunTotal > target Then
            RunTotal = RunTotal - y
            If y.Offset(-1, 0).Interior.ColorIndex = 4 Then
                RunTotal = 0
                If RunTotal = 0 Then y.Interior.ColorIndex = 5
                RunTotal = RunTotal + y
            End If
        End If
    Next y
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:18:10+00:00Added an answer on May 31, 2026 at 6:18 am

    This is maybe what you need (it alternates colors every time the target is reached and carries the balance forward if any):

    Sub calctarget()
        Dim c As Range
        Dim target As Double
        Dim runTotal As Double
        Dim currentColor As Long
    
        target = 44500
        currentColor = 4
    
        For Each c In Range("a1:a15")
            If IsNumeric(c) Then
                runTotal = runTotal + c
            End If
            If runTotal >= target Then 'Target reached
                currentColor = IIf(currentColor = 4, 5, 4) 'alternate colors (4 and 5)
                runTotal = runTotal - target 'maybe you want to start from 0 again?
            End If
            c.Interior.ColorIndex = currentColor
        Next c
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can i make an extension method that will work like this public static
I will try to make this as clear as I can, but if you
How can I make a helper that will tell me how many weeks ago
std::map<std::string, int> m; // Can I make assumption that m[NoSuchKey] will return 0? std::cout
To make this short, I will show what I need exactly. Here is the
I will keep this very short: I'm trying to make a loop through an
Can someone share how to make items in a ListViewer scrollable? Source code will
I'm going to try to explain this best I can I will provide more
How can you setup an app that will ask for permission to access contacts
Will the fact that java class files can be decompiled and need of third

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.