Excel vba: Getting a sum then using that value to figure percentage

OALes

New Member
Joined
May 29, 2024
Messages
7
Office Version
  1. 2016
Platform
  1. Windows
  2. MacOS
I need to sum a column of numbers that always begins at H10 but the last row will vary based on an unknown number of data entries. After I get the total I need to divide by 51 to get the percentage I need.

I have some code that is working on my MacBook, but when I take it to Windows it isn’t working. I’m sorry, I don’t have that code handy. My MacBook runs Excel 365 and the PC runs Excel 2016.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Excel Formula:
=SUM(INDIRECT("H10:H" &ROWS(A:A)))/51
 
Upvote 0
Excel Formula:
=SUM(INDIRECT("H10:H" &ROWS(A:A)))/51
Thank you for the quick response. Can you explain what row(a:a) does? Will that find the last row with contents after row 10 in column H?
 
Upvote 0
Also, that doesn’t look like vba. It looks like a sum in excel?
 
Upvote 0
ROWS(A:A) just returns the total number of rows in Column A. Older versions of Excel had 65536 and newer versions have 1048576.

You could replace that with a number larger than you would ever need if you want.
=SUM(H10:H65000)/51

I don't have a Mac but in PC VBA something like this?

VBA Code:
Range("J1") = Application.WorksheetFunction.Sum(Range("H10:H" & Rows.Count)) / 51
 
Upvote 0
Solution
That looks a lot like what I have which is working on my Mac but not at work where I use a PC. It’s a little different so I’ll try this on Sunday when I’m back at work. Thank you for your ideas. I will let you know what I find.
 
Upvote 0
Perhaps.
Excel Formula:
=SUM(A:A)-SUM(A1:A9)
 
Upvote 0
Forgot the division by 51 above.
Excel Formula:
=(SUM(A:A)-SUM(A1:A9))/51
 
Upvote 0
ROWS(A:A) just returns the total number of rows in Column A. Older versions of Excel had 65536 and newer versions have 1048576.

You could replace that with a number larger than you would ever need if you want.
=SUM(H10:H65000)/51

I don't have a Mac but in PC VBA something like this?

VBA Code:
Range("J1") = Application.WorksheetFunction.Sum(Range("H10:H" & Rows.Count)) / 51
This is exactly what I needed! Thank you so much!
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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