highlight cell if value of cell matches sum of numbers from a column

dzs

New Member
Joined
Jan 15, 2023
Messages
1
Office Version
  1. 2019
Platform
  1. Windows
Hi guys / gals!


Looking for some help from you guys! If there exists a thread with my "problem" please point me in the right direction!
Thank you!

this is the starting table:
View attachment 82850


and i'm looking for this:
snip.1.png


highlight the sum of any two or three cell from column B with the summed value from column A!
Or something similar , maybe not with highlighting cells maybe something in a different column!

Thank you!
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
VBA Code:
Sub combinations()
  Dim items() As Variant
  Dim combLen As Long
  Dim lRowB As Long, lRowA As Long, sum As Double
  lRowA = Cells(Rows.count, 1).End(xlUp).Row
  lRowB = Cells(Rows.count, 2).End(xlUp).Row
  r = 2
  For k = 2 To 3
    combLen = k
    ReDim items(lRowB - 1)
    For i = 2 To lRowB
      items(i - 1) = Cells(i, 2).Value
    Next
    items = binomial(items, combLen)
    
    Application.ScreenUpdating = False
    For i = 1 To nChooseK(lRowB - 1, combLen)
    sum = 0
      For j = 1 To combLen
        Cells(r, j + 3).Value = items(i, j)
      Next
      Cells(r, j + combLen + 1).Value = Application.sum(Range(Cells(r, 4), Cells(r, j + combLen)))
      For l = 2 To lRowA
        If Cells(r, j + combLen + 1).Value = Cells(l, 1).Value Then
          r = r + 1
        End If
      Next
    Next
    Application.ScreenUpdating = True
  Next
End Sub
Function binomial(ByRef v() As Variant, r As Long) As Variant()
  Dim i As Long, k As Long, z() As Variant, comboMatrix() As Variant
  Dim numRows As Long, numIter As Long, n As Long, count As Long
    
  count = 1
  n = UBound(v)
  numRows = nChooseK(n, r)
  
  ReDim z(1 To r)
  ReDim comboMatrix(1 To numRows, 1 To r)
  For i = 1 To r
    z(i) = i
  Next
  Do While (count <= numRows)
    numIter = n - z(r) + 1
    For i = 1 To numIter
      For k = 1 To r
        comboMatrix(count, k) = v(z(k))
      Next
      count = count + 1
     z(r) = z(r) + 1
    Next
    For i = r - 1 To 1 Step -1
      If Not (z(i) = (n - r + i)) Then
        z(i) = z(i) + 1
        For k = (i + 1) To r
          z(k) = z(k - 1) + 1
        Next
        Exit For
      End If
    Next
  Loop
  binomial = comboMatrix
End Function
Function nChooseK(n As Long, k As Long) As Long
  Dim temp As Double, i As Long
  temp = 1
  For i = 1 To k
    temp = temp * (n - k + i) / i
  Next
  nChooseK = CLng(temp)
End Function
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,329
Members
452,635
Latest member
laura12345

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