mtjanousek
New Member
- Joined
- Jul 25, 2018
- Messages
- 17
Hello,
I need to create quite a complex macro and so far I was pretty much unsuccessful.
In the first sheet I have those data (the real sheet has about 4000 rows):
<tbody>
</tbody>
What I need to do is to find the duplicates and merge them in the second sheet while also sum the values for codes starting with a specific letter.
The result should look like this:
<tbody>
</tbody>
As you may see, in the first column I have unique values only (duplicates were merged). In columns B, C, D I have a sum of values for a code starting with a given letter.
In the first sheet, there are codes starting with i.e. KP. I am not interested in those, I am looking for codes matching LI, KA and O only.
Purpose of this macro is to sort out those P-Numbers and show the sum of values for given codes.
So far I tried to merge data using something similar to this: https://www.excelcampus.com/vba/remove-duplicates-list-unique-values/ but that deletes values in rows which I need for sorting. I also tried this approach https://stackoverflow.com/questions...el-and-export-rows-to-another-sheet-using-vba but that's only selecting duplicates, not to mention that I should probably the first sort and merge afterwards.
Would you know how to approach this problem?
I need to create quite a complex macro and so far I was pretty much unsuccessful.
In the first sheet I have those data (the real sheet has about 4000 rows):
P-Number | Note | Code | n/a number | n/a number | Value |
00315678001 | O9873 | 23037 | |||
00345989001 | O9873 | 14535 | |||
00315678001 | O4582 | 14563 | |||
00012345002 | O9837 | 89895 | |||
00315678001 | xx | KP325 | 0 | ||
00345989001 | O1246 | 0 | |||
00315678001 | AK248 | 215079 | |||
00315678001 | KP567 | 0 | |||
00345989001 | KA111 | 9871 | |||
00345989001 | xx | LI1555 | 26050 | ||
00012345002 | VK821 | 1873 | |||
… | … | … | … | … | … |
<tbody>
</tbody>
What I need to do is to find the duplicates and merge them in the second sheet while also sum the values for codes starting with a specific letter.
The result should look like this:
P-Number | LI | KA | O |
00315678001 | 0 | 0 | 37600 |
00345989001 | 26050 | 9871 | 14535 |
00012345002 | 0 | 0 | 91768 |
<tbody>
</tbody>
As you may see, in the first column I have unique values only (duplicates were merged). In columns B, C, D I have a sum of values for a code starting with a given letter.
In the first sheet, there are codes starting with i.e. KP. I am not interested in those, I am looking for codes matching LI, KA and O only.
Purpose of this macro is to sort out those P-Numbers and show the sum of values for given codes.
So far I tried to merge data using something similar to this: https://www.excelcampus.com/vba/remove-duplicates-list-unique-values/ but that deletes values in rows which I need for sorting. I also tried this approach https://stackoverflow.com/questions...el-and-export-rows-to-another-sheet-using-vba but that's only selecting duplicates, not to mention that I should probably the first sort and merge afterwards.
Would you know how to approach this problem?