Hi Everyone,
I am fairly new to VBA after recently undertaking (well, still going) an online VBA course. I've used this forum a lot to learn different code, as although the course is fantastic for building foundations, as you all know, it takes a lot more practice than just a short course to learn VBA. So thank you to all the posters out there that give such detailed answers to help people like me!
I have an issue that I haven't seemed to find a relevant answer for...I am wanting to learn the best VBA code for a quite simple task in Excel without VBA, however I need a macro for this as (using a macro) I am copying data from the same workbook into a new worksheet & then re-pasting the numbers as values (original data is formula referencing another worksheet), but I need some data to be new formula. What I would like to do is look up column A and if it has the word 'total' in it, then sum the corresponding values for that row for all cells above (up to the first blank row - like 'autosum' does).
Here's a quick example - so for the rows that have 'total income' and 'total expenditure', I'd like the other 3 values in that row/s to sum the amounts above
[TABLE="width: 310"]
<colgroup><col><col span="3"></colgroup><tbody>[TR]
[TD]Income[/TD]
[TD]Jan[/TD]
[TD]Feb[/TD]
[TD]Mar[/TD]
[/TR]
[TR]
[TD]Account A[/TD]
[TD="align: right"]10[/TD]
[TD="align: right"]20[/TD]
[TD="align: right"]50[/TD]
[/TR]
[TR]
[TD]Account B[/TD]
[TD="align: right"]10[/TD]
[TD="align: right"]10[/TD]
[TD="align: right"]10[/TD]
[/TR]
[TR]
[TD]Account C[/TD]
[TD="align: right"]10[/TD]
[TD="align: right"]30[/TD]
[TD="align: right"]40[/TD]
[/TR]
[TR]
[TD]Total Income[/TD]
[TD="align: right"]30[/TD]
[TD="align: right"]60[/TD]
[TD="align: right"]100[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]Expenditure[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]Account A[/TD]
[TD="align: right"]10[/TD]
[TD="align: right"]10[/TD]
[TD="align: right"]50[/TD]
[/TR]
[TR]
[TD]Account B[/TD]
[TD="align: right"]20[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]10[/TD]
[/TR]
[TR]
[TD]Account C[/TD]
[TD="align: right"]10[/TD]
[TD="align: right"]15[/TD]
[TD="align: right"]30[/TD]
[/TR]
[TR]
[TD]Total Expenditure[/TD]
[TD="align: right"]40[/TD]
[TD="align: right"]30[/TD]
[TD="align: right"]90[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]Net Profit[/TD]
[TD="align: right"]-10[/TD]
[TD="align: right"]30[/TD]
[TD="align: right"]10[/TD]
[/TR]
</tbody>[/TABLE]
Thank you!
I am fairly new to VBA after recently undertaking (well, still going) an online VBA course. I've used this forum a lot to learn different code, as although the course is fantastic for building foundations, as you all know, it takes a lot more practice than just a short course to learn VBA. So thank you to all the posters out there that give such detailed answers to help people like me!
I have an issue that I haven't seemed to find a relevant answer for...I am wanting to learn the best VBA code for a quite simple task in Excel without VBA, however I need a macro for this as (using a macro) I am copying data from the same workbook into a new worksheet & then re-pasting the numbers as values (original data is formula referencing another worksheet), but I need some data to be new formula. What I would like to do is look up column A and if it has the word 'total' in it, then sum the corresponding values for that row for all cells above (up to the first blank row - like 'autosum' does).
Here's a quick example - so for the rows that have 'total income' and 'total expenditure', I'd like the other 3 values in that row/s to sum the amounts above
[TABLE="width: 310"]
<colgroup><col><col span="3"></colgroup><tbody>[TR]
[TD]Income[/TD]
[TD]Jan[/TD]
[TD]Feb[/TD]
[TD]Mar[/TD]
[/TR]
[TR]
[TD]Account A[/TD]
[TD="align: right"]10[/TD]
[TD="align: right"]20[/TD]
[TD="align: right"]50[/TD]
[/TR]
[TR]
[TD]Account B[/TD]
[TD="align: right"]10[/TD]
[TD="align: right"]10[/TD]
[TD="align: right"]10[/TD]
[/TR]
[TR]
[TD]Account C[/TD]
[TD="align: right"]10[/TD]
[TD="align: right"]30[/TD]
[TD="align: right"]40[/TD]
[/TR]
[TR]
[TD]Total Income[/TD]
[TD="align: right"]30[/TD]
[TD="align: right"]60[/TD]
[TD="align: right"]100[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]Expenditure[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]Account A[/TD]
[TD="align: right"]10[/TD]
[TD="align: right"]10[/TD]
[TD="align: right"]50[/TD]
[/TR]
[TR]
[TD]Account B[/TD]
[TD="align: right"]20[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]10[/TD]
[/TR]
[TR]
[TD]Account C[/TD]
[TD="align: right"]10[/TD]
[TD="align: right"]15[/TD]
[TD="align: right"]30[/TD]
[/TR]
[TR]
[TD]Total Expenditure[/TD]
[TD="align: right"]40[/TD]
[TD="align: right"]30[/TD]
[TD="align: right"]90[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]Net Profit[/TD]
[TD="align: right"]-10[/TD]
[TD="align: right"]30[/TD]
[TD="align: right"]10[/TD]
[/TR]
</tbody>[/TABLE]
Thank you!