-
VBA to export data with altered format to a csv
I have a user with an excel doc formatted like this (source):
Proj |
CostType |
Descr |
2021 |
2022 |
2023 |
2024 |
Proj1 |
CostType1 |
words1 |
123 |
845 |
224 |
|
Proj2 |
CostType2 |
words2 |
|
545 |
|
|
Proj1 |
CostType5 |
words3 |
154 |
|
4456 |
|
Proj3 |
CostType2 |
words4 |
115 |
5445 |
12324 |
|
I've been asked to create a vba script to dump it to a csv file in this format for a bulk upload (target):
Proj |
Description |
CostType1 |
CostType2 |
CostType3 |
CostType4 |
CostType5 |
CostType6 |
CostType7 |
CostType8 |
StartDate |
EndDate |
ExtraCol1 |
ExtraCol2 |
Proj1 |
words1 |
546 |
2112 |
|
124 |
254 |
|
|
|
1-1-2021 |
1-1-2022 |
|
|
Proj2 |
words2 |
456 |
|
454 |
5654 |
|
|
|
|
1-1-2021 |
1-1-2022 |
|
|
Proj1 |
words3 |
54 |
45454 |
|
|
|
|
|
|
1-1-2022 |
1-1-2023 |
|
|
Proj3 |
words4 |
54512 |
121 |
4 |
85 |
|
|
|
|
1-1-2022 |
1-1-2023 |
|
|
I've not tried to iterate in this way before, but it seems like I'd need to start with the date in the source. So, for every row for 2021, I need to grab the first 3 columns and break the costs out for the output, then do the same for 2022. So, I'm essentially switching from dates as columns to cost type as columns. The end date is just the start date + 1 year and they'll always have "1-1-xxxx". Also, the dates in the source extend all the way to 2060. Any one of these columns may be empty. Hope this makes sense. Any help would be greatly appreciated.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules