We’d like to remind Forumites to please avoid political debate on the Forum.

This is to keep it a safe and useful space for MoneySaving discussions. Threads that are – or become – political in nature may be removed in line with the Forum’s rules. Thank you for your understanding.

📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!
The Forum now has a brand new text editor, adding a bunch of handy features to use when creating posts. Read more in our how-to guide

Excel VBA

Hi all,

I have created a macro for my new team at work which automates a lot of manual work they have been needlessly doing for years in Excel. But, sadly, my VBA skills are not as good as I would like them to be and I have hit a deadend.....

Could anyone tell me if it's possible to add text and the sum formula at the bottom of multiple dynamic ranges?

For context, my macro currently pastes data into 12 worksheets (months) and each sheet has between 3 or 5 ranges. At the bottom of each range I would like to add "Total" in column N and the Sum formula in cells O and P.

Thanks in advance for any help.
NSDs: 4/5

Comments

  • PhilCo_2
    PhilCo_2 Posts: 136 Forumite
    The simplest answer is to have them at the top so that they just look at data in the table below. Works better that way if you want to link a summary sheet to the data as well. But if you want them at the bottom of the table you can use something like this to get to the row below the last one with data in..
    Range("A1").Select
    Selection.End(xlDown).Select
    ActiveCell.Offset(1, 0).Select
    

    Which will basically go down column A to the last filled cell. The Offset bit will move 1 cell below. To move 1 cell down and to the right you would use (1, 1). You can then use..
    ActiveCell.Formula =
    

    to enter the data text/formula you want.
  • How are the ranges on each sheet identified? ie are they named ranges or do they have a specific marker that could be used as reference on the sheet (ie each range has the phrase 'Total' in the last row)? Given that these ranges are dynamic (and thus may be of 1 to many rows in length) you need some way of identifying the last row in each range. Potentially this could be identified if there are entirely blank rows between the ranges. Please provide more detail.

    Incidentally, given your exact circumstances, it is likely that FormulaR1C1 will prove more useful for entering the formulas - but again, it would help if you could explain how the ranges can be identified.
This discussion has been closed.
Meet your Ambassadors

🚀 Getting Started

Hi new member!

Our Getting Started Guide will help you get the most out of the Forum

Categories

  • All Categories
  • 353.5K Banking & Borrowing
  • 254.2K Reduce Debt & Boost Income
  • 455K Spending & Discounts
  • 246.6K Work, Benefits & Business
  • 602.9K Mortgages, Homes & Bills
  • 178.1K Life & Family
  • 260.6K Travel & Transport
  • 1.5M Hobbies & Leisure
  • 16K Discuss & Feedback
  • 37.7K Read-Only Boards

Is this how you want to be seen?

We see you are using a default avatar. It takes only a few seconds to pick a picture.