How to format row if sum value of row equal specific value

trungtb

New Member
Joined
Aug 5, 2023
Messages
9
Office Version
  1. 2021
Platform
  1. MacOS
I use excel and i have sheet look like :

A B C
1 3927269 58516305
2 2356361
3 2749088
4 294545
5 13156350
6 1570908
7 1963634
8 5105449
9 3632724
10 3141815
11 7996358
12 3534542
13 29963613
14 .....

Now i want filter all row from 1 -> 13 and highlight specific row only when sum row hightlight = C1
Example : B2+B3+B6 = C1
Now B2,B3,B6 highlight
I using formula on Conditional Formatting look like: =SUM($B$1:B1)=$C$1. But it not working. How to highlight rows only sum value equal specific value ?
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
I don't think this is possible. There could be multiple solutions. Let's say I have a Total in C1 = 9. I could get it with 2 + 2 + 5, or 1 + 1 + 7, or 0 + 0 + 9. If any of these numbers existed in Column B, how would the program know which specific values I was looking for? Now, you may be able to create a Macro which loops through Column B and highlights the first solution it runs across but there still may be other solutions existing in the Column so I don't know if that would exactly solve your problem.
 
Upvote 0
I don't think this is possible. There could be multiple solutions. Let's say I have a Total in C1 = 9. I could get it with 2 + 2 + 5, or 1 + 1 + 7, or 0 + 0 + 9. If any of these numbers existed in Column B, how would the program know which specific values I was looking for? Now, you may be able to create a Macro which loops through Column B and highlights the first solution it runs across but there still may be other solutions existing in the Column so I don't know if that would exactly solve your problem.
I think if we get it with 2 + 2 +5 and then we ignore another result . I only know what row on column B sum value equal C1. If we have mutiple row , please ignore. When i research , another suggest i using resolver. When i using resolver , result not correct. If you have a macro or another solution , please share with me . Thanks you so much
 
Upvote 0
Try this on a copy of your Workbook as unexpected result may occur. This is a VBA solution. I'm not able to do this via Workbook Functions.
VBA Code:
Sub fndSum()
Dim wb As Workbook, ws As Worksheet, rng As Range, cell As Range
Dim num1 As Long, num2 As Long, num3 As Long, fndNum As Long, i As Long
Dim j As Long, k As Long
Set wb = ThisWorkbook
Set ws = wb.ActiveSheet
Set rng = ws.Columns(2)
fndNum = ws.Range("C1").Value
For i = 1 To ws.UsedRange.Rows.Count
    num1 = rng.Cells(i, 1).Value
        For j = i + 1 To ws.UsedRange.Rows.Count
            num2 = rng.Cells(j, 1).Value
                For k = j + 1 To ws.UsedRange.Rows.Count
                    num3 = rng.Cells(k, 1).Value
                    Select Case fndNum
                        Case num1
                            Debug.Print ws.Cells(i, 2).Address
                            ws.Cells(i, 2).Interior.Color = RGB(255, 0, 0)
                            Exit Sub
                        Case num1 + num2
                            Debug.Print ws.Cells(i, 2).Address & "," & ws.Cells(j, 2).Address
                            ws.Cells(i, 2).Interior.Color = RGB(255, 0, 0)
                            ws.Cells(j, 2).Interior.Color = RGB(255, 0, 0)
                            Exit Sub
                        Case num1 + num3
                            Debug.Print ws.Cells(i, 2).Address & "," & ws.Cells(k, 2).Address
                            ws.Cells(i, 2).Interior.Color = RGB(255, 0, 0)
                            ws.Cells(k, 2).Interior.Color = RGB(255, 0, 0)
                            Exit Sub
                        Case num2 + num3
                            Debug.Print ws.Cells(j, 2).Address & "," & ws.Cells(k, 2).Address
                            ws.Cells(j, 2).Interior.Color = RGB(255, 0, 0)
                            ws.Cells(k, 2).Interior.Color = RGB(255, 0, 0)
                            Exit Sub
                        Case num1 + num2 + num3
                            Debug.Print ws.Cells(i, 2).Address & "," & ws.Cells(j, 2).Address _
                            & "," & ws.Cells(k, 2).Address
                            ws.Cells(i, 2).Interior.Color = RGB(255, 0, 0)
                            ws.Cells(j, 2).Interior.Color = RGB(255, 0, 0)
                            ws.Cells(k, 2).Interior.Color = RGB(255, 0, 0)
                            Exit Sub
                    End Select
                Next k
        Next j
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top