Macro to enter AutoSum in the last row of data from Column F:Q

Johnny Thunder

Well-known Member
Joined
Apr 9, 2010
Messages
693
Office Version
  1. 2016
Platform
  1. MacOS
Hello All,


I have a macro that paste data from a master report into tabs (About 12) and
then Hides Column A.

In the same macro I need to add code to the end that will look in all tabs and in Columns F through Q I need to find the last cell with data and make it a SUM formula that will go to the top of the report specifically to cell 3.

So in column F, in the last cell with data it should look something like this =SUM(F3:F"Whatever cell is directly above the formula")

Hope someone knows of a way. Thanks in advance!!!!
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Hi
try these codes. you can run it as an independent macro.
Code:
sub johnny()
dim a as long, b as long, x as long
for a = 1 to sheets.count
for b = 6 to 16
x= worksheets(a).cells(rows.count,b).end(xlup).row
worksheets(a).cells(3,b) = "=sum(" & chr(b+64) & "3:" & chr(b+64) & x & ")"
Next b
Next a
msgbox "Complete"
end sub
Ravi
 
Upvote 0
Ravi,


Where do I apply the rows I want to enter the code into? F:Q are the only columns I need to apply the AutoSum too.
 
Upvote 0
Ravi,



The macro worked but maybe I was unclear about how I needed it to work, Sorry.


How do I get it to locate the last cell with data in column F and then autosum upwards? right now it is starting in row 3 and autosum downwards?
 
Upvote 0
Ravi,


Thank you for the reply. I put the new changes into the spreradsheet and the macro is entering the Auto-Sum under the last line of data? I wanted the macro to replace the last line with the auto-sum?

Is there something else that needs to be changed in the script?
 
Upvote 0
So the macro works but I just need it to put the auto sum in the last row with numbers, right now it is putting the auto sum directly under the last row?

Anyone have any ideas on this?
 
Upvote 0
HI
Try these codes and see if this is what you want.
Code:
sub johnny()
dim a as long, b as long, x as long
for a = 1 to sheets.count
for b = 6 to 16
x= worksheets(a).cells(rows.count,b).end(xlup).row
worksheets(a).cells(x,b) = worksheets(a).cells(x,b) & chr(10) & "Total = " & worksheetfunction.sum(Range((chr(b+64) & "3:" & chr(b+64) & x ))
Next b
Next a
msgbox "Complete"
end sub
ravi
 
Upvote 0
Hey Ravi,

The line
worksheets(a).cells(x,b) = worksheets(a).cells(x,b) & chr(10) & "Total = " & worksheetfunction.sum(Range((chr(b+64) & "3:" & chr(b+64) & x ))

Is all Red when I pasted the macro into VBA? I couldnt figure out what the error is?
 
Upvote 0

Forum statistics

Threads
1,215,588
Messages
6,125,691
Members
449,250
Latest member
azur3

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