Hello all,
I'm currently working on a VBA macro and have a query associated to subtotalling data within one column, down to the last row that contains data within my spreadsheet. The idea is that this macro is dynamic, as the source data will change in volume and therefore value as well.
At the moment, this is the VBA code I have:
Dim LastRow as Long
LastRow = Range("O6").End(xlDown).Row
Range("O4").Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,O7:O" & LastRow & ")"
The above should work by finding the last row in my data, starting from O6. I then subtotal all the data from O7 to the last row of my data, with the formula being located in O4.
With the current data set I am using, my last row is 590. The subtotal does 'work', however it seems to go to line 594 instead. What confuses me even more, is that when I run the macro line by line, it does seem to pick up 590 as the value in 'LastRow'. I've also tried setting LastRow by using rows.count, rather than xlDown, however the end result is the same.
I'd still consider myself quite a 'newbie' when it comes to VBA, so please bare with me if the issue is an obvious one.
Should you require any further information, such as screenshots of what the actual spreadsheet looks like or any further details on the other sections of macro code, let me know.
Thanks in advance for any support you can provide!
I'm currently working on a VBA macro and have a query associated to subtotalling data within one column, down to the last row that contains data within my spreadsheet. The idea is that this macro is dynamic, as the source data will change in volume and therefore value as well.
At the moment, this is the VBA code I have:
Dim LastRow as Long
LastRow = Range("O6").End(xlDown).Row
Range("O4").Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,O7:O" & LastRow & ")"
The above should work by finding the last row in my data, starting from O6. I then subtotal all the data from O7 to the last row of my data, with the formula being located in O4.
With the current data set I am using, my last row is 590. The subtotal does 'work', however it seems to go to line 594 instead. What confuses me even more, is that when I run the macro line by line, it does seem to pick up 590 as the value in 'LastRow'. I've also tried setting LastRow by using rows.count, rather than xlDown, however the end result is the same.
I'd still consider myself quite a 'newbie' when it comes to VBA, so please bare with me if the issue is an obvious one.
Should you require any further information, such as screenshots of what the actual spreadsheet looks like or any further details on the other sections of macro code, let me know.
Thanks in advance for any support you can provide!