-->

Pull Apart Date Range into Separate Cells in CSV,

2019-08-28 22:57发布

问题:

I have a set of dates (a range of years) for each car part in a spread sheet. Each part has a different year range. For example, a muffler fits a Ford Mustang from 1972-1977. A mirror fits a Chevy Chevelle from 1969-1976. There are 8,000 parts listed on the spreadsheet with date (year) ranges in a cell. (The ranges are actually in two cells, first cell is starting year and second cell is ending year). For each part, I need a listing (row) for each year in the range. For example, the muffler for the Mustang would go from one row:

1972-1977 | Ford | Mustang | Muffler

to six rows:

1972 | Ford | Mustang | Muffler
1973 | Ford | Mustang | Muffler
1974 | Ford | Mustang | Muffler

etc. Can I extract these rows from the year range data already contained in the spreadsheet? If so, how?
Thanks!

回答1:

I would try using VBA. First, use excel text to columns and use "-" as a delimiter to put the two years in separate columns. Subtract the years in a new column, so 1980-1977 = 3 in a new column. Then using VBA pull that 3 to count how many rows you want, starting from the lowest year and looping through (3) times.