I have a spreadsheet that has a column of dollar amounts. I need to find a way to compare all of the cells in the column and find ones that add up to a specified value.
![]()
I have a spreadsheet that has a column of dollar amounts. I need to find a way to compare all of the cells in the column and find ones that add up to a specified value.
![]()
Explain in detail
Lets Say I have the following in a spreadsheetOriginally Posted by anilsolipuram
123.66
36276.74
135.67
111.11
333.45
333.79
I need to know what items above will add up to 593.12. I need to be able to type the target number in a cell or VBA box and have it highlight the cells that add up to it.
How many cells we need to consider for adding
It could be up to 2000 cells in the columnOriginally Posted by anilsolipuram
I mean In the given example how many should cell should added up to 593.12,is it 2 cells or 3cells or combination of any number of cells
It could be any number of cells.Originally Posted by anilsolipuram
You need to sort that column as the starting point.
I will get back to you in 1 and 1/2 hours.
I considered 2 cells and 3 cells for summing up finding cells. It can be expanded for any number cells.
Can write a function to simplify this.
Sub macro()
Dim ir As Variant
Dim r As Variant
Dim t As Variant
t = 340
Range("A2").Select
Selection.End(xlDown).Select
ir = ActiveCell.Row
Dim i As Variant
For i = 1 To ir
If Range("a" & i).Value > t Then
r = i
End If
Next
If r = "" Then
r = i
End If
For j = 1 To r - 1
For k = j + 1 To r - 1
'MsgBox Range("a" & j).Value & "," & Range("a" & k).Value
If Range("a" & j).Value + Range("a" & k).Value = t Then
Range("a" & j & ", a" & k).Select
End
End If
Next
Next
For j1 = 2 To r - 1
For j2 = j1 + 1 To r - 1
For j3 = j2 + 1 To r - 1
If Range("a" & j3).Value + Range("a" & j2).Value + Range("a" & j1).Value = t Then
Range("a" & j1 & ",a" & j2 & ",a" & j3).Select
End
End If
Next
Next
Next
End Sub
THANKS FOR YOUR HELPOriginally Posted by anilsolipuram
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks