+ Reply to Thread
Results 1 to 10 of 10

Help with Cell Comparison

  1. #1
    Registered User
    Join Date
    01-07-2005
    Posts
    5

    Help with Cell Comparison

    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.

  2. #2
    Forum Contributor
    Join Date
    11-09-2004
    Posts
    451

    Help with Cell Comparison

    Explain in detail

  3. #3
    Registered User
    Join Date
    01-07-2005
    Posts
    5

    Question

    Quote Originally Posted by anilsolipuram
    Explain in detail
    Lets Say I have the following in a spreadsheet

    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.

  4. #4
    Forum Contributor
    Join Date
    11-09-2004
    Posts
    451
    How many cells we need to consider for adding

  5. #5
    Registered User
    Join Date
    01-07-2005
    Posts
    5
    Quote Originally Posted by anilsolipuram
    How many cells we need to consider for adding
    It could be up to 2000 cells in the column

  6. #6
    Forum Contributor
    Join Date
    11-09-2004
    Posts
    451
    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

  7. #7
    Registered User
    Join Date
    01-07-2005
    Posts
    5
    Quote Originally 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.

  8. #8
    Forum Contributor
    Join Date
    11-09-2004
    Posts
    451
    You need to sort that column as the starting point.

    I will get back to you in 1 and 1/2 hours.

  9. #9
    Forum Contributor
    Join Date
    11-09-2004
    Posts
    451
    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

  10. #10
    Registered User
    Join Date
    01-07-2005
    Posts
    5

    Thanks!!!

    Quote Originally Posted by anilsolipuram
    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 HELP

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1