How do I copy and paste figures but add and replace current figures

ghrek

Active Member
Joined
Jul 29, 2005
Messages
426
Hi

I have a workbook that has 2 sheets the same but with different named tabs. One's called INPUT and the other SUMMARY.

What im trying to do is get a macro that when I click on button it copies the data from cells C7-C35 in the sheet called input and add it to the totals that are already in the same cells on the sheet called summary and paste the new values.

Also need this done on cells G7-G32 from Input to SUMMARY.

What I mean is lets say for instance cell G7 has a value of £1 in the sheet called summary and in sheet called Input it has a value of £10 . I click on the macro button and it transfers and makes the value in sheet called summary £11.

Hope that makes sense and is it possible.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
How about the code below. Note the separate procedure.

VBA Code:
Public Sub ghrek()

    Dim SrceRng As Range, DestRng As Range

    Set SrceRng = ThisWorkbook.Worksheets("Input").Range("C7:C35")
    Set DestRng = ThisWorkbook.Worksheets("Summary").Range("C7:C35")
    AddSomeCells SrceRng, DestRng

    Set SrceRng = ThisWorkbook.Worksheets("Input").Range("G7:G32")
    Set DestRng = ThisWorkbook.Worksheets("Summary").Range("G7:G32")
    AddSomeCells SrceRng, DestRng
End Sub

Public Sub AddSomeCells(ByVal argSrc As Range, ByVal argDest As Range)
    Dim ArrIn As Variant, ArrOut As Variant, i As Long
    ArrIn = argSrc.Value
    ArrOut = argDest.Value
    For i = LBound(ArrIn, 1) To UBound(ArrIn, 1)
        ArrOut(i, 1) = ArrOut(i, 1) + ArrIn(i, 1)
    Next i
    argDest.Value = ArrOut
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,822
Messages
6,121,772
Members
449,049
Latest member
greyangel23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top