OK, now I see what you want to do. Let me elaborate for the sake of the rest of our audience.
This sheet has several columns of numbers, and the rows are grouped so that there are intermittent totals taken using the SUM function. Our user wants to copy just the SUM formulas and paste them into the corresponding places in the other sheet without touching the data.
Excel does not have a built-in way to copy a noncontiguous range and paste it so that it overlays existing cells. If you highlight all the SUM formulas individually (by holding CTRL and clicking), you can copy them all. But when you paste, they will all be pasted contiguously, instead of in the positions that correspond to their positions on Data1.
I have written a macro that can do this for you.
Public Sub CopySumFormulas()
Dim c As Range
For Each c In UsedRange
If Mid(Worksheets("data1").Cells(c.Row, c.Column).Formula, 1, 4) = "=SUM" Then
c.Formula = Worksheets("data1").Cells(c.Row, c.Column).Formula
End If
Next c
End Sub
If you are not familiar with macros, do the following:- In Excel, press ALT-F11. This will bring up the VBA development window; see the attached image.
- On the left you will see a folder list. Look for your Excel file.
- Underneath it you will see a list of the worksheets. Double-click on data2.
- Then on the right side of the screen, paste the code above.
- This is probably a one-time operation, so rather than put buttons on the worksheet, you can just position your cursor somewhere in the code, then press F5 to run the macro.
Bookmarks