Adding a = sum formula to code

Steve001

Board Regular
Joined
Apr 13, 2017
Messages
62
Office Version
  1. 365
  2. 2021
  3. 2013
Platform
  1. Windows
Hi all

Bit stuck, want to look at my sheet and add a = SUM calculation I am using last command to find the last row

last = Cells(Rows.count, "F").End(xlUp).Row

so how do I put into my sheet ?

=SUM(G2:last row)

hope this makes sense

ps please put comments on the example as I am still finding my way round vba

Steve
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try:
Code:
last = Cells(Rows.Count, 6).End(xlUp).Row
Msgbox last
Msgbox "G2"
Msgbox "G2:G"
Msgbox "G2:G" & last
Cells(1, 1).Formula = "=SUM(G2:G" & last)"
Then edit as required.

NB: A1 = row 1, column 1, F7 = row 7, column 6 so Cells(1, 1) = Range("A1"), Cells(7, 6) = Range("F7") etc
 
Upvote 0

Forum statistics

Threads
1,224,930
Messages
6,181,833
Members
453,067
Latest member
mdiz777

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