Dear all,
I need a help to arrange my climate data. I have 30 years of climate data as you can see in the data sheet attached and I want the data to be arranged monthly as you can see in format sheet.
Dear all,
I need a help to arrange my climate data. I have 30 years of climate data as you can see in the data sheet attached and I want the data to be arranged monthly as you can see in format sheet.
So you want the 31 days worth of data from January 1975 to appear in the first 31 cells of column B of the format sheet, then the data from 1976 to appear in the next 31 days, and so on for all the years? That would mean, though, that the data for February would quickly get out of alignment, as there are fewer days in that month, and the same would happen for the four 30-day months. Is that what you want?
Pete
I dont really see how the arraingment you want, is significantly different/better to what you already have? All you are doing is changing rows to columns.
What is your aim with this data?
1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
2. If your question is resolved, mark it SOLVED using the thread tools
3. Click on the star if you think someone helped you
Regards
Ford
yes Pete that is what I want. I know the data length for each month will be different.
It is much different. I want to have all the data for January in one column, February and so on. I am doing a bias correction that demand individual months.
Pete, I can also take each months in a separate worksheet. forinstance, Januarys in sheet 2, Februarys in sheet 3 and so on to avoid any alignment issues. Thanks
If you can add a helper row to contain the days/month, it makes it a lot easier.
I added a row at the top and entered 31/28/30 etc for the days (still working hon how to adjust Feb for leap years)
Also, I changed your month headings from January/February etc to Jan/Feb so both sheets match.
Then I used this, copied down and across, as needed...
=INDEX(Data!$B$2:$AF$378,MATCH($A3-(INT(($A3-1)/B$1)*B$1)&"-"&B$2,Data!$A$2:$A$378,0),1+INT(($A3-1)/B$1))
OK, try this, it should catch leap years in Feb...
=INDEX(Data!$B$2:$AF$378,MATCH($A3-(INT(($A3-1)/B$1)*B$1)&"-"&B$2,Data!$A$2:$A$378,0)+IF(B$2="Feb",IF(MOD(INDEX(Data!$B$1:$AF$1,1+INT(($A3-1)/B$1)),4)=0,1,0)),1+INT(($A3-1)/B$1))
Thanks, where I my copying the script to? can you use my data and attached it so that I can see more clearly? I have limited knowledge in coding
You would copy that into Format sheet B3, then copy down and across as far as you need.
I've been struggling to get one composite formula that you could put into B2 of the Format sheet and just copy across and down. I imagine this is a one-off, so I think the simplest approach is to put this formula in B2:
=INDEX(Data!$B$2:$AF$32,MOD(ROWS($1:1)-1,31)+1,INT((ROWS($1:1)-1)/31)+1)
This can be copied down to the bottom, and it will return all the January data.
You can also copy this across into C2:M2, but before copying it down each column, you will need to make a few changes as shown in colour. The blue-coloured numbers are the number of days in each month, so for March, May, July, August, October and December you can leave those as 31, but for April, June, September and November you should change them to 30 (February is detailed below). You also need to change the range for each month, according to what is used on the Data sheet, i.e. the red numbers. January data covers rows 2 to 32 inclusive, February is in rows 34 to 62, March is 64 to 94, and so on. Once you have made these changes then you can copy the formulae down.
February is unusual because it has a differing number of days, depending on whether it is a leap year or not. The easiest approach to this is to set the blue numbers to 28, but that would mean that you would miss the data for the 29th when it occurs. It might be easier to just put that in manually, rather than devise a complicated formula to just pick up one item of data every 4 years.
Hope this helps.
Pete
Pete, did you see the formula I put together?![]()
Only after I posted mine, as I was trying for quite some time to come up with a way to have MOD(..28) for 28 rows and then MOD(..29) for the next 29 rows, then back to MOD(..28) for the next 84 rows for February, and then gave up and opted for the simpler approach (pragmatist). I was trying to avoid using a helper with this one, although I often do that in my solutions.
Pete
Thanks peter. This work only that it didn't take care of the leap year.
I copy the formula but it doesn't return any value. Do you mean i need to insert rows in the data sheet?
I got around the 28/29 days with this part of the MATCH...
)+IF(B$2="Feb",IF(MOD(INDEX(Data!$B$1:$AF$1,1+INT(($A3-1)/B$1)),4)=0,1,0))
=INDEX(Data!$B$2:$AF$378,MATCH($A3-(INT(($A3-1)/B$1)*B$1)&"-"&B$2,Data!$A$2:$A$378,0)+IF(B$2="Feb",IF(MOD(INDEX(Data!$B$1:$AF$1,1+INT(($A3-1)/B$1)),4)=0,1,0)),1+INT(($A3-1)/B$1))
I could probably have done it without the helper, but the formula was already getting a bit messy...
something like...
+if(or(B$2="Jan",B$2="Mar"etc)1,0) for the month would take care of that
See the attached for how I did this
This solution use no helper in the worksheet.
My approach: with days running from A2:A931=1-930 = 930/31=30 years, I try to define day and year for each row.
i.e A33=32 = day 1 of year 1976 (because 31 = day 31 of previous year 1975)
Stay in B33, d-mmm should be: MOD($A33-1,31)+1&"-"&LEFT(B$1,3) = 1-Jan
Year should be INT(($A33-1)/31)+Data!$B$1 = 1+1975 = 1976
Then, Use INDEX to find the data:
=INDEX(Data!$A$1:$AF$378,MATCH(MOD($A33-1,31)+1&"-"&LEFT(B$1,3),Data!$A$1:$A$378,0),MATCH(INT(($A33-1)/31)+Data!$B$1,Data!$A$1:$AF$1,0))
The final formula in B2:
Drag down and accross.![]()
Please Login or Register to view this content.
Note: 30 Feb, 31 Jun,...display blank.
Quang PT
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks