Divide and export the data according to these instructions

elemelek

New Member
Joined
Jun 7, 2016
Messages
2
Hi MrExcel Community,
my name is Dominika and I'm looking for a VBA code help.
I need to automate some of my Excel work for the sake of completing my dissertation on time, but I'm new to VBA.
I have data that have following columns:
year quarter code number1 number2

The data are properly sorted according to the year, quarter and number1 which are digit data sorted from the smallest to the biggest

All I need is a code in VBA that would make the following

for every year and every quarter
count number of rows in given quarter in given year and save as a variable X
open new file
import the first X/4 integer number of rows
at the end of every quarter add a line with a product from column 'number2' of all imported rows
(repeat the above (create new files with imported data) until all the rows from given year and quarter are imported.)
move to another year and separate the data similar as above and add them as new lines to already existing 4 files.
save and close the files


I want to end up with 4 files containing grouped data that span from 2005 quarter 1 to 2014 quarter 4.

Could you please help me out with converting these instructions into VBA code? :)
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Meggesto

Board Regular
Joined
Mar 8, 2016
Messages
216
Are you trying to build 4 files from raw data that are organized by quarters? Then in each of those 4 files (Quarter 1, 2, 3 & 4), you're organizing it by year? Then you'd like the product of Column "Number 2"? If this is what you're looking to do can you custom sort your data by Quarter, then by Year, then by Column 'Number 2'? That would break your data into 4 blocks that you could simply copy and paste into a new worksheet or workbook.
 

Forum statistics

Threads
1,137,350
Messages
5,680,981
Members
419,947
Latest member
cchristian6

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
Top