add column, modify cell code until last row

zerakh

New Member
Joined
Sep 13, 2020
Messages
6
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
  5. 2011
  6. 2010
  7. 2007
Platform
  1. Windows
I have been trying to figure out how to get a macro/vba script to work, but just can't seem to get all parts to work....

I have the following image from my worksheet with a few buttons.


1600019049183.png

Each Row represents a project type per person (1 person can be on 2 different funded projects). Each row has the same formula all the way down until the last row.
Column AB, Row 9 has a cell formula: =Sum(AG9, AJ9, AM9)
Column AC, Row 9 has a cell formula: =SUM(AH9, AK9, AN9)

It's possible that I get multiple invoices (more than 3) and need to be able to make it easier to add invoice columns. My button (Add Invoice Columns) needs to add a copy of one of the existing invoice columns (AL, AM, & AN) and paste it into the series. But the formulas in the cells AB9 & AC9 need to be updated to include the new column(s). This also needs to continue for the length of column AB & AC until the last used row.

I've tried recording a macro, but it just doesn't seem to be going how I'd like it or how to add in the last row automatically (depending on how many employees I have, the rows will keep adding up). I figure it could use something like: for each row, do something.

VBA Code:
Sub AddInvoiceColumn()

    Columns("AL:AN").Select
    Range("AN1").Activate
    Selection.Copy
    Selection.Insert Shift:=xlToRight
    Range("AB9").Select
    Application.CutCopyMode = False
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "=SUM(RC[5],RC[8],RC[14],RC[11])"
    Range("AC9").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "=SUM(RC[5],RC[8],RC[11],RC[14])"
    Range("AB10").Select
End Sub


Thank you for your assistance.
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Rather than a macro you could use this formula in AB9 & fill down
=SUMIFS(AG9:ZZ9,AG$7:ZZ$7,"Regular")
 
Upvote 0
that is so much easier....thank you!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,780
Messages
6,121,527
Members
449,037
Latest member
tmmotairi

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