Data Sum Up Macro

Rado88

New Member
Joined
Dec 30, 2017
Messages
45
Hi

I'm trying to improve my macro skills and create a MACRO that would calculate sum from purchase/sales made by a client in different offices. However I've encountered some issues and I'm not sure how to proceed further.

Example - I've a data sheet with client name buy amount sell amount and where they were made. It looks like this (the product names and clients are made up, however the data I'm looking for would always be in those columns):
ABCDEFGHIJKLMN
DataDataClient nameDataDataDataDataBuy productBQuantitySell productSell QuantityDataDataData
DataDataJohnxxxDataDataDataWood1000metal555DataDataData
DataDataTimxxxDataDataDataCoal230Wood1000DataDataData
DataDataJohnxxxDataDataDatametal1000Wood220DataDataData
DataDataXyzxxxDataDataDatametal500Coal1000DataDataData
DataDataXyzxxxDataDataDataCoal1000Wood1500DataDataData
DataDataRonxxxDataDataDataWood2500Coal200DataDataData
DataDataRonxxxDataDataDataWood1000metal40DataDataData
DataDataJohnxxxDataDataDataPaper111Wood67DataDataData

<tbody>
</tbody>




The above data will change per each trade date.

What I would like to make from this data table, is to creata a button which whne pressed, would copy the above data into new sheet (created in same workbook) and remove duplicates. At the end it should sum up the sales for each product and add the results with product name name near the client. The end product should look like this in sheet(2):

ABC
Client nameproductQuantity
JohnWood1933
Johnmetal-555
JohnPaper111
RonWood3500
RonCoal-200
Ronmetal-40
TimWood-1000
TimCoal230
XyzWood1500
XyzCoal0
Xyzmetal500

<tbody>
</tbody>

Alternatively the above could be shown in such format

AB
John (in A1 merged with B1)
Wood1933
metal-555
Paper111

<tbody>
</tbody>

It would be easy to sum up the values using sumifs function in my macro, however I'm not sure how to make VBA create a new table each time when the product names and client names will differ (to add search criteria for sumifs). Excel can loop through the data sheet each time new data file is added, but how to make sure that all the products will be added only once (from buy and sell column) and that nothing will be omitted (not to mention the correct format) ;/

The products and clients may change each time a new file with data is copied into macro sheet.

Would it be possible to add a cell colour in the alternative method mentioned above?

Thank you very much in advance for your help :)
 
Last edited:
What line of code gave that error?
 
Upvote 0

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
There is no line highlited. Only The popup with this error appears on vba sheet when you input The Code. When I Run this macro normally (on Excel sheet) it says only object required :(
 
Last edited:
Upvote 0
When you get the error click debug, which line of code gets highlighted?
 
Upvote 0
AoW4sE


I know how to use the debaug option. Unfortunatelly it's not available ;(

It looks like error with yellow triangle from this page

https://stackoverflow.com/questions...-error-424-object-required-when-deleting-rows
 
Last edited:
Upvote 0
If you step through the code using F8, what happens?
 
Upvote 0
It goes to this line and after pressing f8 again The error appears.

The last highlited line:

v1 = Cl.Value & "," & Cl.Offset(, 2).Value
 
Upvote 0
I believe that I managed to fix this issue. I changed The New string value to x instead of v and it starter to work :s

Im not sure why - maybe there was a typo or sth.

Thank you for all the help Fluff

May I only ask one last question?

Is there any Guide on how to work with such Marcos? I mean if I for example had to again add 1 more collumn to sheet 2?
 
Last edited:
Upvote 0
Glad you got it sorted & thanks for the feedback.
Is there any Guide on how to work with such Marcos?
Not sure there is anything dealing with nested dictionaries, but for normal dictionaries have a look here.
 
Upvote 0

Forum statistics

Threads
1,214,990
Messages
6,122,625
Members
449,093
Latest member
catterz66

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