Sum Column B based on Column A using Excel VBA Macro

Rakesh Kamani

New Member
Joined
Feb 25, 2020
Messages
33
Office Version
  1. 2013
Platform
  1. Windows
There are 4 worksheets in the workbook. Command button in sheet 1, project name and actual hours in sheet 2, project name and planned hours based on month and year in sheet 3, final report display on sheet 4. (Name of project, actual hours and planned hours).

When I click on the Command button on Sheet 1, Report Display on Sheet 4 based on Sheet 2 and Sheet 3.

How to write a VBA in this case?

Thank you in advance.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hi and welcome to MrExcel

You could put examples of your sheets 2 and 3.
How do you want the result on sheet 4, showing the previous examples.
And how many records do you have on sheets 2 and 3?
 
Upvote 0
Hi and welcome to MrExcel

You could put examples of your sheets 2 and 3.
How do you want the result on sheet 4, showing the previous examples.
And how many records do you have on sheets 2 and 3?
Thank you for your quick response.

I have unable to attached excel document, so I'm attached snap shot for your reference.
Input.PNG
AH.PNG
PH.PNG
AH_Vs_PH_Report.PNG
 
Upvote 0
Please help me with your examples, I can't capture them from an image.
You can put them with the xl2bb tool.
And you must explain what you need, your examples in image 2 do not match image 1 and image 3 is empty.

 
Upvote 0
Please help me with your examples, I can't capture them from an image.
You can put them with the xl2bb tool.
And you must explain what you need, your examples in image 2 do not match image 1 and image 3 is empty.


1)sheet1: I added command button(Generate report) # When I click on button, the report display in sheet4 - based on sheet2 and sheet3
Generate report

2)Sheet2:(Actual Hours) In this sheet we can consider Project Name and Hours columns only, ignore rest of columns.
Project NameproductDivisionHoursPhase
M312101KeyTD-Pu41
M309401DoorsTDP62
M309201MetalTDS33
M309401IronMR44
M312101MetalEX25

3)Sheet3: (Planned Hours): we can consider from march to june(2020/03 to 2020/06)
2020/012020/022020/032020/042020/052020/06
M327905-A M SYC SBW138.50125.62152140125.32362.14
M309201-A M SYC SBW25658532.50145.6385
M309401-A MM SYMC SBW145.3236.1423.5612536512
M327905-A M SYC SBW25.2336545.1221.425.3621.3
M312101- SYMC SBW54.325.632412.53314.23
M327905-A MM_225.323.125.3645.8578.0665

4)Sheet4: (Final Report)# Currently I filled manually for your reference.
Project NameActual HoursPlanned Hours
M3121016260.76
M30940110525.56
M3092013348.13
M327905892.64
M327905-A MM_2214.27
Total192241.36


Thank you in advance

Thanks,
Rakesh Kamani
 
Last edited by a moderator:
Upvote 0
You could upload a copy of your file to a free site such www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. If the workbook contains confidential information, you could replace it with generic data.
 
Upvote 0
Hi DanteAmor, I know that uploading to a file sharing site would be better but the data in post number 5 can be copied (At least I can). Column and row references might be an issue though..
 
Upvote 0
Column and row references might be an issue though..
Hi Mark, thanks for your comments.

In addition to the fact that rows and columns are not visible in the ranges, I see other problems.
In the pictures:
- It has merged cells.
- The projects are in a row and apparently the amount to be added is in another row.
- According to the example of ranges should only add from March to June, but I do not see where to get that range of months.

I am inclined to take the data from the images since the ranges do not look real. I make the first proposal and see how it works.
 
Upvote 0
Hi @Rakesh Kamani.

The date on sheet 2 is a real date or text.
How can I know which dates to add?
In your image periods 12, 01, 02, 03 are merged in 2 columns, but 04 is merged in 3 columns, is that so?
Any particular reason?
 
Upvote 0
Hi @Rakesh Kamani.

1582821484289.png


Sorry, but I have more doubts.
In your image, you have the M327905 project, it has 2 values: 47.87 and 31.58, But in that group I also see the value: 67.50.
But I also see a total, which does not seem like a value: 139/136.

You could comment, for that project which is the result you need.
 
Upvote 0

Forum statistics

Threads
1,215,049
Messages
6,122,864
Members
449,097
Latest member
dbomb1414

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