ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Find what numbers add up to a specific number (https://www.excelbanter.com/excel-worksheet-functions/225377-find-what-numbers-add-up-specific-number.html)

heathersm1

Find what numbers add up to a specific number
 
Hello,

I would like to know if there is a function which I could use to search a
column to find values which would equal a certain value.

For instance I have a list of:

1
2
8
98
65
45
25
98

I would like to search that column for any of those values which would add
to 123. The function would then return or highlight the 98 and 25 because
those add up to 123.

Is there a way I can do this?

Thanks for your help!

Gary''s Student

Find what numbers add up to a specific number
 
See:

http://www.tushar-mehta.com/excel/te...olver_Template


--
Gary''s Student - gsnu200840


"heathersm1" wrote:

Hello,

I would like to know if there is a function which I could use to search a
column to find values which would equal a certain value.

For instance I have a list of:

1
2
8
98
65
45
25
98

I would like to search that column for any of those values which would add
to 123. The function would then return or highlight the 98 and 25 because
those add up to 123.

Is there a way I can do this?

Thanks for your help!


Jacob Skaria

Find what numbers add up to a specific number
 
Try the below code

HighlightParent 500, 1
500 is the sum
1 is the column number

Sub HighlightParent(lngSum As Long, lngCol As Long)
Dim lngRow, lngRows, lngTRow
lngRows = ActiveSheet.Cells(Rows.Count, lngCol).End(xlUp).Row
For lngRow = 1 To lngRows
For lngTRow = lngRow To lngRows
If Cells(lngRow, lngCol) + Cells(lngTRow, lngCol) = lngSum Then
Cells(lngRow, lngCol).Interior.Color = vbYellow
Cells(lngTRow, lngCol).Interior.Color = vbYellow
Exit Sub
End If
Next
Next
End Sub


"heathersm1" wrote:

Hello,

I would like to know if there is a function which I could use to search a
column to find values which would equal a certain value.

For instance I have a list of:

1
2
8
98
65
45
25
98

I would like to search that column for any of those values which would add
to 123. The function would then return or highlight the 98 and 25 because
those add up to 123.

Is there a way I can do this?

Thanks for your help!



All times are GMT +1. The time now is 01:21 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com