Macro variable column length sum

uncleslinky

New Member
Joined
Mar 31, 2009
Messages
47
hi there
Is there a way to change the code below so that when I sum data excel doesn't go to row "30000"
If possible I would like it to stop at the last cell of data in cell A


Code:
Dim r As Long
r = Cells(Rows.Count, "A").End(xlUp).Row
    
    ActiveCell.FormulaR1C1 = "=SUMIF(R2C3:R30000C3,RC3,R2C[-12]:R30000C[-12])"
    Selection.AutoFill Destination:=Range("U2:U" & r)

As you can see I have done this for the last line of code where it copies down the formula, however I can't figure out how to do this on the 3rd line of code
Thanks
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Code:
Dim r As Long
r = Cells(Rows.Count, "A").End(xlUp).Row
    
    ActiveCell.FormulaR1C1 = "=SUMIF(R2C3:R" & r & "C3,RC3,R2C[-12]:R" & r & "C[-12])"
    Selection.AutoFill Destination:=Range("U2:U" & r)
 
Upvote 0
hi, thats great thanks!

Can i just ask another quick question...

Do you know of a way I can add together the last cell in column J, M, N, O and record this at the bottom of column T, offset by 5 rows

Thanks again
 
Upvote 0
This should work

Code:
sub Test()

dim lRow as long
lRow = sheets("MySheetName").Range("A1048576").end(xlup).row ' if using XL03, change the 1048576 to 65536

Sheets("MySheetName").Range("T" & lRow + 5).FormulaR1C1 = "=SUM(R" & lRow & "C10,R" & lRow & "C13:R" & lRow & "C15)"

End sub

You are basically building strings from defined data and variables.
 
Upvote 0

Forum statistics

Threads
1,224,617
Messages
6,179,915
Members
452,949
Latest member
beartooth91

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