Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Matching Cell Contents

Status
Not open for further replies.

V00D00

Technical User
Jul 11, 2005
78
US
I need some help setting this up and I am at a loss at where to start. Below is my basic requirement.

If cell(A1) from sheet1 matches cell(A1) from sheet2 then add to sheet2 cell(23) and cell(24) with the value from sheet1 cell(12) and cell(13). Repeat for each cell in column A until no more data exists.

Thanks for the help.
 
Hi there,

Not sure if I understood you correctly or not, but maybe ..

Code:
Sub AddValuesPlease()
    Dim ws1 As Worksheet, ws2 As Worksheet, i As Long, LastRow As Long
    Set ws1 = Sheets("Sheet1")
    Set ws2 = Sheets("Sheet2")
    LastRow = ws1.Cells(ws1.Rows.Count, 1).End(xlUp).Row
    For i = 1 To LastRow
        If ws1.Cells(i, 1).Value = ws2.Cells(i, 1).Value Then
            ws1.Cells(i + 11, 1).Value = ws1.Cells(i + 11, 1).Value + ws2.Cells(i + 22, 1).Value
            ws1.Cells(i + 12, 1).Value = ws1.Cells(i + 12, 1).Value + ws2.Cells(i + 23, 1).Value
        End If
    Next i
End Sub

Please save your workbook before running (so if it does not produce desired results, you can get the original data back - or run on test data). If this is not what you desired, please post back some more details with some examples of the expected outcome.

-----------
Regards,
Zack Barresse
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top