+ Reply to Thread
Results 1 to 7 of 7

finding value of cell from sum cells gives same value

Hybrid View

  1. #1
    Registered User
    Join Date
    03-09-2015
    Location
    tripoli,libya
    MS-Off Ver
    2010
    Posts
    3

    finding value of cell from sum cells gives same value

    hello guys,
    am trying to make an excel sheet in my work , and i have got a serious problem.

    the problem is:let us assume that i have in cell (A1)450 and in cell (b1)200
    (b2)250
    (b3)300
    (b4)150

    what i want to do is to highlight any cells if i sum 2 or more of them can be equals to my A1 cell in this case if i sum B1 and B2 it will be = to A1
    same goes B3 and B4


    i dont know if this can be done in excel or not,but any idea is appreciate.
    Last edited by mgstar; 03-10-2015 at 04:33 PM.

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: complicated formula

    You could try this macro

    Option Explicit
    
    Sub Test()
    Dim MyRange As Range
    Dim N As Integer
    Dim NBinary As String
    Dim RangeComb As Long
    Dim X As Long
    Dim Total As Long
    
    Set MyRange = Range(Cells(1, 2), Cells(Rows.Count, 2).End(xlUp))
    MyRange.Interior.ColorIndex = xlNone
    RangeComb = 2 ^ MyRange.Count
    
    For N = 1 To RangeComb - 1
        NBinary = Left("0000000000000000", Len(RangeComb) - Len(DecToBin(Str(N)))) & DecToBin(Str(N))
        Total = 0
        For X = 1 To MyRange.Count
            If Mid(NBinary, X, 1) = "1" Then
                Total = Total + MyRange(X)
            End If
        Next X
        
        If Total = Range("A1") Then
            For X = 1 To MyRange.Count
                If Mid(NBinary, X, 1) = "1" Then
                    MyRange(X).Interior.ColorIndex = 4
                Else
                    MyRange(X).Interior.ColorIndex = xlNone
                End If
            Next X
            Exit Sub
        End If
        
    Next N
    
    End Sub
    
    
    Function DecToBin(ByRef D As String) As String
        Dim N As Long
        Dim Res As String
        For N = 31 To 1 Step -1
            Res = Res & IIf(CLng(D) And 2 ^ (N - 1), "1", "0")
        Next N
        N = InStr(1, Res, "1")
        DecToBin = Mid(Res, IIf(N > 0, N, Len(Res)))
    End Function
    Open up the VBA editor by hitting ALT F11

    Insert a new module by hitting Insert - Module

    Paste the macro into the empty sheet

    Hit ALT F11 to get back to the worksheet.

    Run the macro by going to tools-macro in Excel 2003 or the view ribbon in Excel 2007/2010.
    Martin

  3. #3
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: complicated formula

    Please take a moment to read the forum rules and then amend your thread title to something descriptive of your problem - not what you think the answer might be. (think google search terms?). Once you have done this please send me a PM and I will remove this request. (Also, include a link to your thread - copy from the address bar)

    Many members search our previous posts, and thread titles play a big part of the search. I doubt anybody would do a search based on your title?

    To change a Title on your post, click EDIT POST then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  4. #4
    Registered User
    Join Date
    03-09-2015
    Location
    tripoli,libya
    MS-Off Ver
    2010
    Posts
    3

    Re: complicated formula

    master mrice thank you very much you

  5. #5
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,612

    Re: need help down here

    Don't think you'll get much luck with that new title...

  6. #6
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: need help down here

    mgstar, hiow is that any more descriptive than your 1st title?

  7. #7
    Registered User
    Join Date
    03-09-2015
    Location
    tripoli,libya
    MS-Off Ver
    2010
    Posts
    3

    Re: need help down here

    FDibbins, I think you may suggest a title for me

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Need help with complicated formula(s)
    By kyleporter in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-23-2014, 11:08 AM
  2. check a cell for a certain time and day of week
    By garyfahy in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-16-2014, 07:39 AM
  3. Need help with a complicated If Formula
    By Chris602 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-23-2014, 04:14 PM
  4. Rather Complicated Formula
    By paulmaddock in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-08-2008, 09:36 AM
  5. [SOLVED] Complicated Formula
    By Stephen in forum Excel General
    Replies: 12
    Last Post: 04-17-2005, 09:06 AM

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