Need to replace cell references

johnsvikings

New Member
Joined
Dec 3, 2018
Messages
8
Hello,

I have 4 worksheets in my workbook labeled, Baltimore, Owings_Mills, Towson and Westminister. Column A has a title in cell A1, A2 is blank and additional subtitles in cells A3 & A4 and then the names of the customers in cells A5 to the bottom row (this is never the same number of rows each time this report is ran and also varies from worksheet to worksheet. Columns B-G and Column J have numbers in them but the total in the last row is a fixed number and I need to change that to a sum of all the numbers beginning 1 row above the totals to up to row 5.

My current Macro reads like this but will not work the next time when the number of rows of data will change and I need help replacing the:
"ActiveCell.FormulaR1C1 = "=COUNTA(R[-27]C:R[-1]C)" portions so they will vary with the number of rows rather than only going up a fixed number of rows as it does now.

Sheets("Baltimore").Select
Application.Goto Reference:="R3C1"
Selection.End(xlDown).Select
ActiveCell.FormulaR1C1 = "=COUNTA(R[-27]C:R[-1]C)"
ActiveCell.Offset(0, 1).Range("A1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=SUM(R[-27]C:R[-1]C)"
ActiveCell.Offset(0, 1).Range("A1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=SUM(R[-27]C:R[-1]C)"
ActiveCell.Offset(0, 1).Range("A1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=SUM(R[-27]C:R[-1]C)"
ActiveCell.Offset(0, 1).Range("A1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=SUM(R[-27]C:R[-1]C)"
ActiveCell.Offset(0, 1).Range("A1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=SUM(R[-27]C:R[-1]C)"
ActiveCell.Offset(0, 1).Range("A1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=SUM(R[-27]C:R[-1]C)"
ActiveCell.Offset(0, 3).Range("A1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=SUM(R[-27]C:R[-1]C)"
ActiveCell.Offset(1, 0).Range("A1").Select
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
To begin in row 5 use
Code:
ActiveCell.FormulaR1C1 = "=COUNTA(R5C:R[-1]C)"
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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