"SUM" Based on Description

Panoos64

Well-known Member
Joined
Mar 1, 2014
Messages
882
Hi all, i would like to "SUM" the below numbers using a VBA code which should base on description in col. "AK". In F.1. are the original data and in Sch.2. is the expected result. Therefore that the rows are not stably and are change due to accounts which have movement for each month.
Thanking you in advance

Sch.1.
AKALAMAN
546TOTAL REVENUE:-50,555.00
547
548COST OF SALES8,150.00
549ELECTRICIYT3,125.00
550WATER SUPPLY1,245.00
551PRINTING & STATIONERY874.00
552HEATING & LIGHTING2,896.00
553REPAIRS & MAINTENANCE4,258.00
554RATES & LICENSES1,368.00
555ADMINISTRATION EXPENSES2,562.00

<tbody>
</tbody>


Sch.2.
AKALAMAN
546TOTAL REVENUE:-50,555.00
547
548COST OF SALES8,150.00
549ELECTRICIYT3,125.00
550WATER SUPPLY1,245.00
551PRINTING & STATIONERY874.00
552HEATING & LIGHTING2,896.00
553REPAIRS & MAINTENANCE4,258.00
554RATES & LICENSES1,368.00
555ADMINISTRATION EXPENSES2,562.00
556
557TOTAL EXPENSES24,478.00
558
559NET PROFIT / LOSS-26,077.00

<tbody>
</tbody>
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Thank you for advice Joe. but i cannot find the right formula. Is there any easy method to create the above VBA code ? Thanks for your support
 
Last edited:
Upvote 0
Are you just trying to get lines 557 and 559?
If not, please describe your requirements in more detail.
 
Upvote 0
Hi Joe, Please note that the rows ARE NOT FIXED and so i would like to "SUM" at first the expenses, which start from 2nd row below "TOTAL REVENUE:" (1st row is blank) which on above example is the row 548 till the 1st blank row which is 556 and should prepare the sum and the description in col. "AK" "TOTAL EXPENSES" which code should write. Then the "SUM" between "TOTAL REVENUE:" and "TOTAL EXPENSES" and code should write the description "NET PROFIT / LOSS" IN col. "AK"
Thank u so much for ur support
 
Upvote 0
Is a VBA solution acceptable?
 
Upvote 0
Yeap, i know that there is solution by VBA and no other way can resolve my project and also I know how to create some VBA, by recording macro but the above is little bit complicate and due to that, i am newbie regarding VBA is the reason that i required a support.

In points the code should be as follows:

- Should run through col. "AK" and where find the text "TOTAL REVENUE:" should start "SUM" the below accounts till the next blank row.
- The "SUM" should be placed offset 3 columns in "AN" and parallel should enter the description in col. "AK" "TOTAL EXPENSES".
- Then the code should "SUM" in col. "AN" the rows which contains the descriptions in col "AK" "TOTAL REVENUE:" and "TOTAL EXPENSES", leaving a blank row below text "TOTAL EXPENSES"
- The code should enter description in col."AK" "NET PROFIT / LOSS"

Thank you for your interesting to resolve my project
 
Upvote 0
Try this:
Code:
Sub MyMacro()

    Dim row1 As Long
    Dim row2 As Long
    
'   Find "TOTAL REVENUE:" in column AK
    Columns("AK").Find(What:="TOTAL REVENUE:", After:=Range("AK1"), LookIn:= _
        xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
        xlNext, MatchCase:=False, SearchFormat:=False).Activate
        
'   Capture location of total revenue row
    row1 = ActiveCell.Row
        
'   Find last row of data in section below that
    row2 = Cells(row1 + 2, "AK").End(xlDown).Row
    
'   Insert Total Expenses two rows below
    Cells(row2 + 2, "AK") = "TOTAL EXPENSES"
    Cells(row2 + 2, "AN").Formula = "=SUM(AN" & row1 + 2 & ":AN" & row2 & ")"
    
'   Insert Net Profit/Loss line
    Application.ScreenUpdating = True
    Cells(row2 + 4, "AK") = "NEW PROFIT / LOSS"
    Cells(row2 + 4, "AN") = "=AN" & row1 & " - AN" & row2 + 2
    
End Sub
 
Upvote 0
Well done Joe!! I appreciated so much for what you done for me. You resolved my project and due to the above i will save many hours, preparing the above report, instead to process it by manual method. Many thanks for you time spent for me and i express my best wishes to you. Have a great lovely day!
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,517
Members
448,968
Latest member
Ajax40

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