+ Reply to Thread
Results 1 to 11 of 11

Update several cells based on entry

Hybrid View

  1. #1
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Update several cells based on entry

    This isn't the programming forum, but your question clearly states "how to change the value in the original cell based on two matching criteria".

    To change the actual value in the original cells automatically requires a macro, VBA. This macro does that:
    Option Explicit
    
    Sub AmtAdjuster()
    Dim ws1 As Worksheet    'sheet with controlling values
    Dim ws2 As Worksheet    'data sheet to adjust
    Dim RNG As Range
    
    Set ws1 = Sheets("Sheet1")
    Set ws2 = ActiveSheet       'run the macro from the sheet to adjust
    
    If ws2.Name = ws1.Name Then
        MsgBox "Please activate the data sheet to adjust before running the macro." _
            & vbLf & "Aborting..."
        Exit Sub
    End If
    
    With ws2
        On Error Resume Next
        Set RNG = .Range("B:B").SpecialCells(xlConstants, xlNumbers)
        
        If Err.Number > 0 Then
            MsgBox "No numbers where found in column B." & vbLf & "Please check data layout and try again." _
                & vbLf & vbLf & "(Nb in column A, Amt in column B)"
            Exit Sub
        End If
        
        RNG.Offset(, 24).FormulaR1C1 = _
            "=IF(AND(INDEX(Sheet1!C4, MATCH(RC1, Sheet1!C1, 0))=Sheet1!R4C7,INDEX(Sheet1!C3, MATCH(RC1, Sheet1!C1, 0))<Sheet1!R4C8), Sheet1!R4C10, RC2)"
        RNG.Value = RNG.Offset(, 24).Value
        RNG.Offset(, 24).ClearContents
        MsgBox "Done"
    End With
        
    End Sub


    I've attached your sheet with the macro already installed, you need only put your values in columns A:B and click the button to run the adjuster.

    The macro is actually using a worksheet formula to decide which values to change, putting that formula into column AA, then copying the resulting values over the original values in column B.

    The formula being used is this...place it in D3 and copy down to see it work:

    =IF(AND(INDEX(Sheet1!$D:$D, MATCH('Sheet1 (2)'!$A3, Sheet1!$A:$A, 0))=Sheet1!$G$4,INDEX(Sheet1!$C:$C, MATCH('Sheet1 (2)'!$A3, Sheet1!$A:$A, 0))<Sheet1!$H$4), Sheet1!$J$4, $B3)
    Attached Files Attached Files
    Last edited by JBeaucaire; 01-09-2011 at 07:50 PM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

+ 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