PDA

View Full Version : SUM multiple COLUMNS DATA with common HEADER NAME



Qavi
02-03-2021, 07:55 AM
Dear VBA Gurus,

sir, I'm new to macros in excel. i dont have any knowledge of programming, I work as a Jr.Accountant , i have a situation to prepare the SUMMARISED DATA based on the sheets in excel file. ill list details of the sheet content in POINTS BELOW.

1.I have a excel file with 12 Sheets (each month of year , from Jan to Dec)
2.I have 195 Columns (Maximum) per sheet (Jan 195 Columns, Feb - 177 Columns & so on...)
3.My data for calculation starts from Column 10(J) in each sheet
4.I have 2 Headers, 1st Header is DAY of the month (01,02,03...28/31)
5.Each Day has SUBHEADER under which there are 6 Columns with SUBHEADING (G,D,M,F,C,O), for each day it will repeat
6. I want to SUM all the columns with G as Subheader from J to last column and post its SUM in Column 4(D) ,
D as SUBHEADER from J to last column and post its SUM in Column 5(E),
M as SUBHEADER from J to last column and post its SUM in Column 6(F),
F as SUBHEADER from J to last column and post its SUM in Column 7(G),
C as SUBHEADER from J to last column and post its SUM in Column 58(H),
O as SUBHEADER to from J to last column and post its SUM in Column 9(I)
7.It must add all the existing rows in the sheet
8.It must repeat for all the Sheets (12 Sheets)

for ex, in Jan month there are 31 times G Column and the rest of all columns come 31 times.

I'm introduced to MACROS in excel for the first time.
hope you understand my question (in points),
Kindly I request you to provide me with the VBA code.

i have attached the screenshot of the excel sheet.
Thanks
Qavi

p45cal
02-03-2021, 05:01 PM
1. I've got ideas but I need to test them so could you supply a workbook with this sort of data in?
2. What version of Excel are you using?
3. Do you have the FILTER function available in that version?

Qavi
02-03-2021, 10:35 PM
Dear Sir,

Many Many Thanks for the reply, i appreciate lots to you, for your nice gesture.

1.Im attaching the excel file with that data
2.Excel version is 2019
3.FILTER Function is not available in 2019 it seems i searched in google and writing it.

Thanks in advance
Qavi

p45cal
02-04-2021, 04:20 PM
In your sheets, ensure that the range D2:I2 is the same as in your picture with msg#1 above.
Then put this macro into a standard code-module:
Sub blah()
For Each Sht In ThisWorkbook.Worksheets
x = Application.Match(Left(Sht.Name, 3), Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Now", "Dec"), 0)
If Not IsError(x) Then
Sht.Range("D3:I81").FormulaR1C1 = "=SUMIF(R2C10:R2C195,R2C,RC10:RC195)+SUMIF(R2C10:R2C195,R2C,R[1]C10:R[1]C195)"
'sht.Range("D3:I81").Value = sht.Range("D3:I81").Value 'optional line to convert the formulae to plain values.
End If
Next Sht
End Sub

Will only affect sheets whose name's first 3 letters are the first 3 letters of English months.
See comment in the code too.
See attached. Button at cell N4 of Jan-21 sheet.

Qavi
02-06-2021, 12:01 AM
Dear Sir,

I'l check and update you,
Many Thanks in Advance

Qavi

Qavi
02-06-2021, 12:15 AM
Dear Sir,

Perfectly Working..... 100%.

Thanks a Lot.
Appetite your kind help.

:clap::clap::clap::yes:yes:yes
Qavi