Updating formuals afer a copy

This macro is executed on the form button labeled “Add Summary Year”.
Sub InsertNewYearConsolidated()
    Dim ws As Worksheet, rw As Long
    Set ws = Worksheets("Consolidated")
    ws.Select
    
    'Insert 12 rows above Totals and the spacer row
    rw = ws.Range("A:A").Find("Totals").Row
    ws.Rows(((rw - 1) & ":" & (rw + 10))).Insert Shift:=xlDown
    
    'copy the format from the first 12 rows (6 to 17)
    ws.Range("A6:U17").Copy
    ws.Range("A" & (rw - 1)).Select
    Selection.PasteSpecial Paste:=xlPasteFormats
   Application.CutCopyMode = False
    Range("A6:A17").Select
    Selection.Copy
    Range("A18:A29").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("A1").Select
End Sub

Open in new window

The above code produces the following results (I’ve provided just a portion)
 FormulasIn row 31 the formula in place do not reflect the new the changes in the ranges of the formulas. Let me give you an example. Before I update, the formula in C19 is =Sum(C6:C17). After the update in cell C31 the formula should be =Sum(C6:C29) instead of =Sum(C6:C17). I need a way to update the formulas when the Consolidated sheet is added
Frank FreeseAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Glenn RayExcel VBA DeveloperCommented:
Change your SUM formulas to include the row immediately above the formula.  For example,
C19:  =SUM(C6:C18)


-Glenn
0
Frank FreeseAuthor Commented:
That I understand - but the client wants this done for them. I just don't know how to macro update the formulas in Row 31.
As I've mentioned before, the client thinks a macro is a fish. With that being said I guess a micro is a small fish :)
0
Ejgil HedegaardCommented:
Change formula to Sum(C6:C18) to include empty row 18, then the formula will fit the new range when the rows are inserted.

Besides that, don't use the fixed range Range("A18:A29").Select when you insert the values.
Use the dynamic range like the code above copying the format.
ws.Range("A" & (rw - 1)).Select

Change
 
Range("A6:A17").Select
    Selection.Copy
    Range("A18:A29").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False

Open in new window

to
ws.Range("A6:A17").Copy
    ws.Range("A" & (rw - 1)).Select
    Selection.PasteSpecial Paste:=xlPasteValues

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Frank FreeseAuthor Commented:
that works! thank you
0
Frank FreeseAuthor Commented:
thanks folks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.